
PK 
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Attribute extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'attributes';
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'parentattr_id','attribute_name','attribute_slug','attribute_desc','attribute_sortby','isactive','isdelete','addedby','created_at','updated_at','deleted_at','visitor'
];
/**
* tree view a query show tree.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function attrHierarchicalTree()
{
$attributes = Attribute::select('id','category_id','category_ids','parentattr_id','attribute_name','attribute_slug')->orderBy('attribute_sortby','asc')->get()->toArray();
//$attributes = Attribute::all()->sortByDesc('attribute_sortby')->toArray();
return $attributes = buildAttrTree($attributes);
//$attributes = Attribute::orderBy('attribute_sortby','asc')->get()->toArray();
//$attributes = Attribute::with('children')->get()->toArray();
//$queries = DB::getQueryLog(); p($queries);
}
/**
* Scope a query to only include active users.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeActive($query)
{
return $query->where('isactive', 1);
}
/**
* Get the index name for the model.
*
* @return string
*/
public function category()
{
return $this->belongsTo('App\Category');
}
}


PK 99