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
'remote_img_lg' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => 'https://domain.com/w/500',
'visibility' => 'public',
'throw' => false,
]
'remote_img_lg' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => 'https://domain.com/w/500',
'visibility' => 'public',
'throw' => false,
]
but when I use it in the component the src attribute of the img tag is not set.
Solution:
Oh right. It's requiring $state. ->getStateUsing(fn ($record) => 'https://domain.com/w/500'.$record->your_image_column)
Jump to solution
4 Replies
Dennis Koch
Dennis Koch6mo ago
depending on context
What 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)
ChickenDev
ChickenDevOP6mo ago
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
Dennis Koch
Dennis Koch6mo ago
Oh right. It's requiring $state. ->getStateUsing(fn ($record) => 'https://domain.com/w/500'.$record->your_image_column)
ChickenDev
ChickenDevOP6mo ago
Brilliant! That worked, thanks.
Want results from more Discord servers?
Add your server