*/ protected $fillable = [ 'name', 'picture' ]; // * EVENTS /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { static::creating(function (self $model) { self::manageFields($model); }); static::updating(function (self $model) { self::manageFields($model); }); static::updated(function (self $model) { FileStorageHelper::removeOldFile($model, 'picture'); }); static::deleted(function (self $model) { FileStorageHelper::removeFile($model, 'picture'); }); } // * METHODS /** * Common methods function. * * @param self $model * @return void */ private static function manageFields(self $model) { $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); } // * RELATIONSHIPS /** * Product relation * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function products(): HasMany { return $this->hasMany(Product::class); } }