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
toeknee5mo ago
try: ->limit(1)
bionary
bionaryOP5mo ago
just found that! It works perfectly, thanks
toeknee
toeknee5mo ago
Welcomes!
bionary
bionaryOP5mo 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
toeknee5mo 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
bionaryOP5mo 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
toeknee5mo ago
So do that with: ->collection()
bionary
bionaryOP5mo 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