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 #2OP2y ago
anyone?
jackleblackdev
jackleblackdev14mo ago
same question ?
ericmp #2
ericmp #2OP14mo ago
wdym? u have the same question?
Lara Zeus
Lara Zeus14mo ago
maybe
->getStateUsing(function($record){
return $record->relationOrAttr;
})
->getStateUsing(function($record){
return $record->relationOrAttr;
})
Majid Al Zariey
Majid Al Zariey8mo 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()
)
)

Did you find this page helpful?