How to manually pick a single image to display on a column from multiple images?
Lets say I have 3 images, by default in the table the last image is picket. How do I control this and pick the first one?
6 Replies
Maybe with getStateUsing(). https://filamentphp.com/docs/2.x/tables/columns/getting-started#calculated-state
Filament
Getting started - Columns - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
Yeh, it looks like it worked but behaviour is a bit odd.
By default I expect that this is the first image in orderable image component, but actually it's the last one. :/
@awcodes also do you know if it's possible to get
->collection('products')
property value inside a getStateUsing
so I would not need to repeat myself?
Ah, managed to get it, just leaving for reference if anyone will need it. π
Well, you're using
last()
to get the image from the collection. If you want the first one, use first()
insteadYeh but it's the other way around, with the last I ma getting first, and with the first I am getting last right now. π
Atleast in my case, each product can have multiple images, and normally the first one in the grid should be the main one but for some odd reason first for the component is the last item in the grid. π€