F
Filament11mo ago
Igor

spatie/laravel-medialibrary fallback image do not work

I'm have a optional image field and I want to show a default image if any image was added, According to the spatie documentation if I add fallback urls and path to collection should be enough, but the image column do not show the fallback image, it's a bug or I'm doing wrong?
Solution:
Ya, I'm not sure if that useFallbackUrl or useFallbackPath works. But using ->defaultImageUrl('/images/anonymous.png') on the Resource works....
Jump to solution
3 Replies
Solution
DrByte
DrByte11mo ago
Ya, I'm not sure if that useFallbackUrl or useFallbackPath works. But using ->defaultImageUrl('/images/anonymous.png') on the Resource works.
DrByte
DrByte11mo ago
On further digging, on the docs page at https://spatie.be/docs/laravel-medialibrary/v11/working-with-media-collections/defining-media-collections#content-defining-a-fallback-url-or-path it explains that the fallback is for generated conversions, and is used when getFirstMediaUrl or getFirstMediaPath are called. But Filament's package doesn't call those methods. It calls getAvailableUrl ( https://github.com/filamentphp/filament/blob/a8725b51b6ce352ff4527f885c14f1824597a6dc/packages/spatie-laravel-media-library-plugin/src/Tables/Columns/SpatieMediaLibraryImageColumn.php#L70 ) ... which I think is actually appropriate.
GitHub
filament/packages/spatie-laravel-media-library-plugin/src/Tables/Co...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
DrByte
DrByte11mo ago
I'm not sure if it would make sense to call getFirst if getAvailable is null. Could explore that, and if it has benefit then a PR could be submitted. Would be needed for all at least the 2 display-components in that package.
Want results from more Discord servers?
Add your server