I try to get latest 10 products with its images but only the first image so that is what i try
$newProducts = \App\Product::latest()->with(['images', function($el){
$el->first();
}])->with('category')->take(10)->get();
but it gives me this error
mb_strpos() expects parameter 1 to be string, object given
it has a morph
relation between product
and image
Product Model
class Product extends Model {
public function images()
{
return $this->morphMany(Image::class, 'imageable');
}
}
Image Model
class Image extends Model {
public function imageable()
{
return $this->morphTo();
}
}