*/ protected $fillable = [ 'type', 'name', 'picture', 'picture_alt', 'picture_title', 'published', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => ApproachTypeEnum::class, 'published' => 'boolean' ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { static::creating(function (self $approach) { $approach->picture = FileStorageHelper::storeFile($approach, $approach->picture, true); }); static::updating(function (self $approach) { $approach->picture = FileStorageHelper::storeFile($approach, $approach->picture, true); }); static::updated(function (self $approach) { FileStorageHelper::removeOldFile($approach, 'picture'); }); static::deleted(function (self $approach) { FileStorageHelper::removeFile($approach, 'picture'); }); } // * RELATIONSHIPS /** * Get MainSlides of the Approach (morph-to-many relationship). * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function mainSlides(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(MainSlide::class); } }