spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

Changing file_name doesn't sync file on disk #3587

Closed michele-grifa closed 6 months ago

michele-grifa commented 7 months ago

I want to edit the file_name of a media, but after save, the file on the filesystem, doesn't sync and have the old name.

$media = Media::find($id);
$media->file_name = $name;
$media->name = $name;
$media->save();

Laravel Version: 9.52.16 Spatie Version: 10.15.0

timvandijck commented 6 months ago

This is expected behaviour. In your code sample you are retrieving the Eloquent model and updating it in the database, no file is touched when doing it like this.

If you want to update the file on disk you will need to do this yourself.