¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -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();