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:Jump to solution
Ya, I'm not sure if that
useFallbackUrl
or useFallbackPath
works.
But using ->defaultImageUrl('/images/anonymous.png')
on the Resource works....3 Replies
Solution
Ya, I'm not sure if that
useFallbackUrl
or useFallbackPath
works.
But using ->defaultImageUrl('/images/anonymous.png')
on the Resource works.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.Defining media collections | laravel-medialibrary
laravel-medialibrary
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
I'm not sure if it would make sense to call get
First
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.