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.
![](https://utfs.io/f/a9c62113-08e7-45f2-924e-911d8bfdd0bf-1nq2cb.png)
By default I expect that this is the first image in orderable image component, but actually it's the last one. :/
![](https://utfs.io/f/bf80b44f-b98a-4a1f-b84d-78e2aeed5a8b-1nq2cb.png)
@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. π€