Laravel-medialibrary: getMedia by it's id

Created on 1 Sep 2018  路  2Comments  路  Source: spatie/laravel-medialibrary

Is there a simple way to get media by id?
getMedia method has a 2nd parameter for filtering

Tried this one but it's not good:
$primary_image = $this->getMedia('images', [ 'id' => 44 ])->first();

Thanks

Most helpful comment

Got it, my solution is:

    $images = $this->getMedia('images');
    $image = $images->where('id', $this->primaryMediaId)->first();

All 2 comments

Got it, my solution is:

    $images = $this->getMedia('images');
    $image = $images->where('id', $this->primaryMediaId)->first();

Just chain it.
$images = $this->getMedia('images')->where('id', $this->primaryMediaId);

Was this page helpful?
0 / 5 - 0 ratings