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