*/ protected $fillable = [ 'title', 'video_id', 'product_id', 'is_on_homepage', 'order', 'published', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'published' => 'boolean', 'is_on_homepage' => 'boolean', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { static::creating(function (self $video) { self::setOrder($video); }); } // * METHODS /** * Set order after the last element of the list. * * @param self $model * @return void */ private static function setOrder(self $model): void { $model->order = \intval(self::query()->max('order')) + 1; } // * RELATIONSHIPS /** * Get the product for the video. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function product(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Product::class); } }