Laravel get a collection of relationship items

后端 未结 4 1072
难免孤独
难免孤独 2021-01-07 18:01

I\'m stuck on this what seems like a simple task.

I have a User that has many Shops that have many Products..

I\'m trying to get all the Pr

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 18:19

    You can use this :

    \Auth::user()->shops()->with('products')->get()->pluck('products')->flatten();
    

    if you don't want replicate, you can use ->unique()

提交回复
热议问题