¨4.0.1¨
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Modules\Brand\Entities;
|
||||
|
||||
use Modules\Media\Entities\File;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Brand\Admin\BrandTable;
|
||||
use Modules\Support\Eloquent\Model;
|
||||
use Modules\Media\Eloquent\HasMedia;
|
||||
@@ -11,25 +12,31 @@ use Modules\Product\Entities\Product;
|
||||
use Modules\Meta\Eloquent\HasMetaData;
|
||||
use Modules\Support\Eloquent\Sluggable;
|
||||
use Modules\Support\Eloquent\Translatable;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Brand extends Model
|
||||
{
|
||||
use Translatable, Sluggable, HasMedia, HasMetaData;
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['translations'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['slug', 'is_active'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
@@ -38,14 +45,6 @@ class Brand extends Model
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
|
||||
/**
|
||||
* The attribute that will be slugged.
|
||||
*
|
||||
@@ -53,6 +52,33 @@ class Brand extends Model
|
||||
*/
|
||||
protected $slugAttribute = 'name';
|
||||
|
||||
|
||||
/**
|
||||
* Find a specific brand by the given slug.
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function findBySlug($slug)
|
||||
{
|
||||
return self::where('slug', $slug)->firstOrNew([]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get brand list.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public static function list()
|
||||
{
|
||||
return Cache::tags('brands')->rememberForever(md5('brands.list:' . locale()), function () {
|
||||
return self::all()->sortBy('name')->pluck('name', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
@@ -63,6 +89,7 @@ class Brand extends Model
|
||||
static::addActiveGlobalScope();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get public url for the brand.
|
||||
*
|
||||
@@ -73,63 +100,44 @@ class Brand extends Model
|
||||
return route('brands.products.index', $this->slug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a specific brand by the given slug.
|
||||
*
|
||||
* @param string $slug
|
||||
* @return self
|
||||
*/
|
||||
public static function findBySlug($slug)
|
||||
{
|
||||
return self::where('slug', $slug)->firstOrNew([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get brand list.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function list()
|
||||
{
|
||||
return Cache::tags('brands')->rememberForever(md5('brands.list:' . locale()), function () {
|
||||
return self::all()->sortBy('name')->pluck('name', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the brand's logo.
|
||||
*
|
||||
* @return \Modules\Media\Entities\File
|
||||
* @return File
|
||||
*/
|
||||
public function getLogoAttribute()
|
||||
{
|
||||
return $this->files->where('pivot.zone', 'logo')->first() ?: new File;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the brand's banner.
|
||||
*
|
||||
* @return \Modules\Media\Entities\File
|
||||
* @return File
|
||||
*/
|
||||
public function getBannerAttribute()
|
||||
{
|
||||
return $this->files->where('pivot.zone', 'banner')->first() ?: new File;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get related products.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
* @return HasMany
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get table data for the resource
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function table()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user