Closed mistre83 closed 6 years ago
Use your own model and add the methods you need there: https://docs.spatie.be/laravel-medialibrary/v7/advanced-usage/using-your-own-model
Or you can just call the relationship:
$post = Post::find(1);
$items = $post->media;
// $items is a Illuminate\Database\Eloquent\Collection instance
The core of the HasMediaTrait
relies on that polymorphic relationship:
/**
* Set the polymorphic relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function media()
{
return $this->morphMany(config('medialibrary.media_model'), 'model');
}
The method getMeida()
only filters the collection.
In version 4 of Media library the method
getMedia
returned all the collections. So, if my object has 3 collections, that method return all.Now, in version 5 the
getMedia
have as default parameterdefault
.There is a way to get all the media as in version 4?
The only trick i've found is to call getMedia with empty string
->getMedia('')
Thanks