'json', 'details' => 'json', ]; /** * The attributes that should be cast. * * @var array */ protected $enumCasts = [ 'type' => InputTypeEnum::class, 'status' => InputStatusEnum::class, ]; /** * The "booted" method of the model. * * @return void */ protected static function booted(): void { static::creating(function (self $model) { static::setSlug($model); static::setStatusField($model); static::setOrder($model); }); static::updating(function (self $model) { static::setSlug($model); }); } // * METHODS /** * Set the slug. * * @param self $model * * @return void */ private static function setSlug(self $model) { $model->slug = Str::slug($model->name); } /** * Set the status field. * * @param self $model * * @return void */ private static function setStatusField(self $model) { if (!isset($model->status)) { $model->status = InputStatusEnum::default(); } } /** * 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; } }