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
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?Just use the default TextColumn
https://filamentphp.com/docs/3.x/tables/columns/relationships#counting-relationships
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
I just use