F
Filament4mo ago
Keika

spatie media library count in column

Hi, Im guessing it's simple but I can't find how. Using the Spatie Media library plugin, how can I simply display the number of media per model in a table? So if my modelhas 3 images, I want to display 3, using SpatieMediaLibraryImageColumn. Is that possible?
4 Replies
ChesterS
ChesterS4mo ago
I mean, you don't need the SpatieMediaLibraryImageColumn if you're not showing the images? Why not just use a text column and use ->formatStateUsing() to show the number?
Keika
KeikaOP4mo ago
ok thanks, I've started doing that,but I'm kinda in a bind TextColumn::make, expects a column or relationship. Im already displaying all columns, and I don't know what relationship to create. Ive looked at spatie's docs, and can't find anything related to relationships nevermind: MorphMany Relationship: The HasMedia trait automatically adds a media() method to your model. This method defines a MorphMany relationship, linking your model to the Media model. thanks Google AI column to use is media
toeknee
toeknee4mo ago
I just use
->formatStateUsing(fn ($record) => $record->getMedia('*')->count()),
->formatStateUsing(fn ($record) => $record->getMedia('*')->count()),

Did you find this page helpful?