In this case, you can use lazy loading :
auth()->user()->load('shops.products');
To sort through products:
@foreach (auth()->user()->shops as $shop)
@foreach ($shop->products as $product)
{{ $product->name }}
@endforeach
@endforeach
If you only need products:
Product::whereHas('shop', function ($q) {
$q->where('user_id', auth()->id());
})->get();
In both cases, you will have the same number of database queries, so I would use the first example in a real application.
source
share