*/ #[\Override] protected $fillable = [ 'name', 'picture', 'picture_alt', 'picture_title', ]; // * EVENTS /** * Perform any actions required after the model boots. */ protected static function booted(): void { static::creating(function (self $model): void { self::manageFields($model); }); static::updating(function (self $model): void { self::manageFields($model); }); static::updated(function (self $model): void { FileStorageHelper::removeOldFile($model, 'picture'); }); static::deleted(function (self $model): void { FileStorageHelper::removeFile($model, 'picture'); }); } // * METHODS /** * Common methods function. */ private static function manageFields(self $model): void { $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); } // * RELATIONSHIPS /** * Product relation. * * @return HasMany */ public function products(): HasMany { return $this->hasMany(Product::class); } /** * Activities logs One-to-many relationship. * * @return HasMany */ public function activityLogs(): HasMany { return $this->hasMany(ActivityLog::class); } }