¨4.0.1¨
This commit is contained in:
@@ -60,30 +60,12 @@ class Category extends Model
|
||||
*/
|
||||
protected $slugAttribute = 'name';
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::addActiveGlobalScope();
|
||||
}
|
||||
|
||||
public static function findBySlug($slug)
|
||||
{
|
||||
return static::with('files')->where('slug', $slug)->firstOrNew([]);
|
||||
}
|
||||
|
||||
public function isRoot()
|
||||
{
|
||||
return $this->exists && is_null($this->parent_id);
|
||||
}
|
||||
|
||||
public function url()
|
||||
{
|
||||
return route('categories.products.index', ['category' => $this->slug]);
|
||||
}
|
||||
|
||||
public static function tree()
|
||||
{
|
||||
@@ -96,6 +78,7 @@ class Category extends Model
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static function treeList()
|
||||
{
|
||||
return Cache::tags('categories')->rememberForever(md5('categories.tree_list:' . locale()), function () {
|
||||
@@ -107,6 +90,7 @@ class Category extends Model
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static function searchable()
|
||||
{
|
||||
return Cache::tags('categories')
|
||||
@@ -122,21 +106,48 @@ class Category extends Model
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::addActiveGlobalScope();
|
||||
}
|
||||
|
||||
|
||||
public function isRoot()
|
||||
{
|
||||
return $this->exists && is_null($this->parent_id);
|
||||
}
|
||||
|
||||
|
||||
public function url()
|
||||
{
|
||||
return route('categories.products.index', ['category' => $this->slug]);
|
||||
}
|
||||
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'product_categories');
|
||||
}
|
||||
|
||||
|
||||
public function getLogoAttribute()
|
||||
{
|
||||
return $this->files->where('pivot.zone', 'logo')->first() ?: new File;
|
||||
}
|
||||
|
||||
|
||||
public function getBannerAttribute()
|
||||
{
|
||||
return $this->files->where('pivot.zone', 'banner')->first() ?: new File;
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$attributes = parent::toArray();
|
||||
|
||||
Reference in New Issue
Block a user