ImageEntry src URL
I have a database column that contains a relative URL that, depending on context, needs to have a different domain and path prepended to it.
For example,
the DB column value is
/bysZeUvSPZPJnku4qkHF34CdgMG.jpg
and the same filename is used for a thumbnail using the https://domain.com/w/100
prefix and for the main image using the https://domain.com/w/500
prefix.
How can I prepend these values to the ImageEntry component?
I have tried creating a special disk inside filesystems.php
using the following config
but when I use it in the component the src
attribute of the img
tag is not set.Solution:Jump to solution
Oh right. It's requiring
$state
. ->getStateUsing(fn ($record) => 'https://domain.com/w/500'.$record->your_image_column)
4 Replies
depending on contextWhat context? If you are using disks it checks whether the file exists first. I'd try using
->getStateUsing(fn ($state) => 'https://domain.com/w/500'.$state)
The context meaning where in the app the image is being displayed. The API source uses the same filename for many different image sizes using the prefix.
Where do I apply this function? I added it to the ImageEntry::make chain, but it resulted in an infinite loop. I don't see documentation for this function anywhere on the Filament documentation pages.
Solution
Oh right. It's requiring
$state
. ->getStateUsing(fn ($record) => 'https://domain.com/w/500'.$record->your_image_column)
Brilliant! That worked, thanks.