'boolean', ]; /** * The attributes that are translatable. * * @var array */ public $translatedAttributes = ['name']; /** * The attribute that will be slugged. * * @var string */ protected $slugAttribute = 'name'; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { static::addActiveGlobalScope(); } /** * Get public url for the brand. * * @return string */ public function url() { 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 */ public function getLogoAttribute() { return $this->files->where('pivot.zone', 'logo')->first() ?: new File; } /** * Get the brand's banner. * * @return \Modules\Media\Entities\File */ public function getBannerAttribute() { return $this->files->where('pivot.zone', 'banner')->first() ?: new File; } /** * Get related products. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function products() { return $this->hasMany(Product::class); } /** * Get table data for the resource * * @return \Illuminate\Http\JsonResponse */ public function table() { return new BrandTable($this->newQuery()->withoutGlobalScope('active')); } }