'Quảng cáo', 'promotion' => 'Chương trình khuyến mãi', ]; public const PUBLIC_FIELDS = ['id', 'title', 'type', 'image_url', 'link_url', 'open_in_new_tab']; protected $fillable = [ 'title', 'type', 'image_path', 'link_url', 'open_in_new_tab', 'is_active', 'starts_at', 'ends_at', 'sort_order', ]; protected $casts = [ 'open_in_new_tab' => 'boolean', 'is_active' => 'boolean', 'starts_at' => 'datetime', 'ends_at' => 'datetime', 'sort_order' => 'integer', ]; protected $appends = ['image_url']; public function getImageUrlAttribute(): string { return Storage::disk(self::DISK)->url($this->image_path); } public function scopeVisible(Builder $query): Builder { return $query->where('is_active', true) ->where(fn (Builder $q) => $q->whereNull('starts_at')->orWhere('starts_at', '<=', now())) ->where(fn (Builder $q) => $q->whereNull('ends_at')->orWhere('ends_at', '>=', now())) ->orderBy('sort_order') ->orderBy('id'); } /** * @return list> */ public static function publicList(): array { return self::visible()->get() ->map(fn (self $banner) => $banner->only(self::PUBLIC_FIELDS)) ->all(); } }