Is possible to use SpatieMediaLibraryImageColumn to retrieve an image of a relation model?

this is the way i do it when the table's query is the model that has the spatie image:
SpatieMediaLibraryImageColumn::make('image')->collection('image')
SpatieMediaLibraryImageColumn::make('image')->collection('image')
but now im in another table, which relates to previous one, and i need to retrieve the image of the related model. idk how to do it
SpatieMediaLibraryImageColumn::make('relatedModel.image')->collection('image') // doesn't work
->relationship() // also tried using relationship, but - Method Filament\Tables\Columns\SpatieMediaLibraryImageColumn::relationship does not exist.
SpatieMediaLibraryImageColumn::make('relatedModel.image')->collection('image') // doesn't work
->relationship() // also tried using relationship, but - Method Filament\Tables\Columns\SpatieMediaLibraryImageColumn::relationship does not exist.
5 Replies
ericmp #2
ericmp #2OP16mo ago
anyone?
jackleblackdev
jackleblackdev12mo ago
same question ?
ericmp #2
ericmp #2OP12mo ago
wdym? u have the same question?
Lara Zeus
Lara Zeus12mo ago
maybe
->getStateUsing(function($record){
return $record->relationOrAttr;
})
->getStateUsing(function($record){
return $record->relationOrAttr;
})
Majid Al Zariey
Majid Al Zariey7mo ago
I used the following
Tables\Columns\ImageColumn::make('images')->getStateUsing(fn($record) =>
$record->relationship?->getMedia("collection_name")
->map(fn($image) =>
$image->getPathRelativeToRoot()
)
)
Tables\Columns\ImageColumn::make('images')->getStateUsing(fn($record) =>
$record->relationship?->getMedia("collection_name")
->map(fn($image) =>
$image->getPathRelativeToRoot()
)
)
Want results from more Discord servers?
Add your server