2👍
✅
If you have relations in reviews
for user
, you can do this.
return $product->load('categories' , 'images', 'reviews', 'reviews.user');
Some helpful link.
Good luck!
1👍
public function show(Product $product)
{
return $product->load('categories', 'images', 'reviews.user');
}
Or some advance level if you want to perform where query or access query builder
public function show(Product $product)
{
return $product->load([
'categories',
'images',
'reviews' => function ($query) {
$query->where('field', 'value')->with('user');
},
]);
}
Source:stackexchange.com