*/ protected $fillable = [ 'id', 'title', 'starts_at', 'ends_at', 'is_visible', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'starts_at' => 'datetime', 'ends_at' => 'datetime', 'is_visible' => 'boolean', ]; /** * Translatable attributes. * * @var array */ public $translatable = ['title']; /** * Related products. */ public function products(): BelongsToMany { return $this->belongsToMany(Product::class) ->withTimestamps(); } /** * Active flash sales are visible and inside their timer window. */ public function scopeActive(Builder $query): Builder { return $query ->where('is_visible', true) ->where('starts_at', '<=', now()) ->where('ends_at', '>', now()); } }