filament/forms
3.2.90
11.10.0
3.5.0
8.2.20
The FileUpload component is prefixing the stored file path with storage/
prefix when displaying the file (image) preview. This approach is correct for displaying an image.
When Laravel Accessor is created on the attribute with file path to add the storage/
prefix when using the file path attribute elsewhere on the website. Then, Filament forcefully adds the storage/
prefix anyway, thus not finding the file (image).
That behaviour than makes Filament think, that no file is there -> no file is displayed -> when the model is saved, the value is set to null.
The FileUpload component should have an option to disable the automatic prefixing to enable the developer to add it themselves globally.
storage/
prefix to the attribute that stores the file path (example value: img/event/something.jpg
)Note: In this example, a default image path is being set if the attribute is null. This is not exactly necessary to reproduce the issue, but serves as an example of practical use.
protected function image(): Attribute
{
return Attribute::make(
get: fn (?string $value) => Storage::url($value ?? self::DEFAULT_IMAGE),
);
}
Forms\Components\FileUpload::make('image')
->visibility('public')
->directory('img/event')
->image()
->downloadable()
->openable(),
https://github.com/davmarek/filament-issue-fileupload
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too