Laravel get a collection of relationship items
what you need is a relationship between the User Model and the Product Model ..
this is possible using hasManyThrough
relationship ..
USER MODEL
public function products()
{
return $this->hasManyThrough('App\Product', 'App\Shop')
}
now, you can access all the user's products with
Auth::user()->products;
You can use this :
\Auth::user()->shops()->with('products')->get()->pluck('products')->flatten();
if you don't want replicate, you can use ->unique()
If you want to directly work on a query (for performances):
Product::whereHas('shops', function($query){
$query->where('user_id', auth()->user()->id);
})->get();