You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using a custom model for my Media Library and it is extending the MediaCollections Media model as a BaseModel.
This is, among others, for creating a relationship between the media files and a tags entity I have.
Between the media and labels I've a pivot table called media_tag and in both my Media model and my Tag model I've made a many-to-many relationship between them.
In Tinker, when querying the custom model directly I get the tags (\App\Models\Media::find(5)->tags will produce a collection of Tag models).
However, if I want to attach these Media models to another model called MediaLibrary and retrieve all the medias (Tinker: \App\Models\MediaLibrary::where('tenant_id', 1)->first()->getMedia('tenant_id_1')[0] it is returning me a Spatie\MediaLibrary\MediaCollections\Models\Media model and not the custom model. So getting the tags for that media \App\Models\MediaLibrary::where('tenant_id', 1)->first()->getMedia('tenant_id_1')[0]->tags will result in null.
I can of course do something like \App\Models\Media::find($media_entry_from_medialibrary->id)->tags but that seems a bit lengthy.
My question is: Making a custom model and defining it in the media library config why are this not returning a MediaCollection of the custom model?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all,
I'm using a custom model for my Media Library and it is extending the
MediaCollections Media model
as a BaseModel.This is, among others, for creating a relationship between the
media files
and atags
entity I have.Between the media and labels I've a pivot table called
media_tag
and in both myMedia
model and myTag
model I've made a many-to-many relationship between them.In Tinker, when querying the custom model directly I get the tags (
\App\Models\Media::find(5)->tags
will produce a collection ofTag models
).However, if I want to attach these Media models to another model called
MediaLibrary
and retrieve all the medias (Tinker: \App\Models\MediaLibrary::where('tenant_id', 1)->first()->getMedia('tenant_id_1')[0]
it is returning me aSpatie\MediaLibrary\MediaCollections\Models\Media
model and not the custom model. So getting the tags for that media\App\Models\MediaLibrary::where('tenant_id', 1)->first()->getMedia('tenant_id_1')[0]->tags
will result innull
.I can of course do something like
\App\Models\Media::find($media_entry_from_medialibrary->id)->tags
but that seems a bit lengthy.My question is: Making a custom model and defining it in the
media library config
why are this not returning a MediaCollection of the custom model?Beta Was this translation helpful? Give feedback.
All reactions