*/ protected $fillable = [ 'name', 'type', 'picture', 'picture_alt', 'picture_title', 'price', 'arcadia_id', 'arcadia_weight', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => SellItemsType::class, ]; /** * Perform any actions required after the model boots. */ protected static function booted(): void { static::creating(function (self $model) { self::setOrder($model); $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); }); static::updating(function (self $model) { $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); }); static::updated(function (self $model) { FileStorageHelper::removeOldFile($model, 'picture'); }); static::deleted(function (self $model) { FileStorageHelper::removeFile($model, 'picture'); }); } // * METHODS /** * Set model's order after the last element of the list. */ private static function setOrder(self $mainSlide): void { $mainSlide->order = \intval(self::query()->max('order')) + 1; } /** * Getter html_name. */ public function getHtmlNameAttribute(): string { return nl2br(strip_tags($this->name)); } /** * Convert the model instance to an array. * * @return array> */ public function toArray(): array { return array_merge(parent::toArray(), [ 'htmlName' => $this->htmlName, ]); } }