*/ protected $fillable = [ 'id', 'app', 'title', 'description', 'place', 'link', 'is_visible', 'resource_id', 'resource_type', 'sort_order', 'options', ]; /** * Transtable fields * * @var array */ public array $translatable = ['title', 'description']; /** * Sortable attributes * * @var array */ public $sortable = [ 'order_column_name' => 'sort_order', 'sort_when_creating' => true, ]; /** * Category */ public function category(): BelongsTo { return $this->belongsTo(Category::class, 'resource_id'); } /** * Collection */ public function collection(): BelongsTo { return $this->belongsTo(Collection::class, 'resource_id'); } /** * Brand */ public function brand(): BelongsTo { return $this->belongsTo(Brand::class, 'resource_id'); } /** * Media collections */ public function registerMediaCollections(): void { $this->addMediaCollection('main') ->singleFile(); } /** * Media conversations */ public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('thumb50x50') ->width(50) ->height(50); $this->addMediaConversion('thumb350x350') ->width(350) ->height(350); $this->addMediaConversion('thumb650x650') ->width(650) ->height(650); } /** * Thumbnail */ public function thumbnail(string $resolution = '50x50'): string { return $this->getFirstMediaUrl('main', 'thumb'.$resolution); } /** * Scope to filter * * @param mixed $query * @param string $attribute * @param string $value * @return $query */ public function scopeFilter($query, $attribute, $value): Builder { return $value ? $query->where($attribute, $value) : $query; } /** * Main image */ public function image(): string { return $this->getFirstMediaUrl('main'); } /** * Text color */ public function textColor(): string { return $this->options->get('color') ?? ''; } /** * Places for banner * * @return string */ public static function places(): array { return [ 'homepage' => __('Homepage'), ]; } /** * Attachable resourcec to banner */ public static function attachableResources(): array { return [ 'brand' => __('Brand'), 'category' => __('Category'), 'collection' => __('Collection'), ]; } }