How do I eager load media that returns a url of each image conversion in the JSON response? · Issue #1388 · spatie/laravel-medialibrary

PHOTO EMBED

Tue Mar 23 2021 07:21:24 GMT+0000 (Coordinated Universal Time)

Saved by @stewardjornsen

protected $appends = ['profile_thumbnail','thumbnail'];

public function getProfileThumbnailAttribute()
{
    //Check if media has collection and return default.jpg if false
    if ($this->media->isEmpty()) {
        return 'default.jpg';
    } else {
        return $this->media->first()->getUrl('profile_thumbnail');
    }  
}

public function getThumbnailAttribute()
{
    //Check if media has collection and return default.jpg if false
    if ($this->media->isEmpty()) {
        return 'default.jpg';
    } else {
        return $this->media->first()->getUrl('thumbnail');
    }  
}
content_copyCOPY

https://github.com/spatie/laravel-medialibrary/issues/1388