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'); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter