Level 2
I solved it, it was a simple forgetfulness:
return 'img/annuncio/'.$this->id.'/'.$this->thumb->filename;
Hi, I would like to get a single image (if the user has uploaded one or more images) and I created this function, but I think I'm wrong with the polymorphy.
Item.php
function getThumb()
{
if ($this->thumb()->exists()) {
return 'img/annuncio/'.$this->id.'/'.$this->filename;
} else {
return 'img/components/no_images.jpg';
}
}
public function thumb()
{
return $this->morphOne(Image::class, 'imageable');
}
Image.php
public function imageable()
{
return $this->morphTo();
}
Please or to participate in this conversation.