0

I'm creating an e-commerce in laravel and vue js. I am in the following situation

    public function show(Product $product){
    return $product -> load('categories' , 'images', 'reviews');
}

From this through an axios I can trace all my tables connected to the products. Now, however, I would need to trace from reviews also the users table with which they have a connection. How can I do this on my controller? Such a thing

return $ product -> load ('categories', 'images', 'reviews' -> with ('user');

2 Answers2

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!

mare96
  • 3,749
  • 1
  • 16
  • 28
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');
        },
    ]);
}
AH.Pooladvand
  • 1,944
  • 2
  • 12
  • 26