Show First image: SpatieMediaLibraryImageColumn

How can I limit the "thumb" image in my table to the first image only when my record has more than one Spatie Media records associated? I am using SpatieMediaLibraryImageColumn and always have several media images related...but they are cluttering up the table. I want to show the first one only. I thought I could directly fetch what I need (pseudo-code): ->getStateUsing(fn($record) => $record->getFirstMedia()...) But, it appears that ->getStateUsing() is ignored completely
Solution:
try: ->limit(1)...
Jump to solution
8 Replies
Solution
toeknee
toeknee4mo ago
try: ->limit(1)
bionary
bionaryOP4mo ago
just found that! It works perfectly, thanks
toeknee
toeknee4mo ago
Welcomes!
bionary
bionaryOP4mo ago
Is there a reason ->getStateUsing() doesn't work? in my case I'm all good...for now, but what if I wanted to get a bit more choosy with which image shows... As in pick a different image based on some values I have stored in the custom_properties field of the table.
toeknee
toeknee4mo ago
Yeah, its a specific field type that doesn't have support for it. If you were converting the image properly you can set the conversion that you want to call too.
bionary
bionaryOP4mo ago
I was thinking I could get clever and use field: collection_name to isolate an image...but that feels a bit hacky to me.
toeknee
toeknee4mo ago
So do that with: ->collection()
bionary
bionaryOP4mo ago
indeed. Since all I need is the first image (luckily) I'm all good with ->limit(1) for now thank you
Want results from more Discord servers?
Add your server