通過自定義數據透視表 (related_teams) 在同一模型(團隊模型)上具有 belongsToMany 關系我的關系如下現在附加和分離工作正常,但是正如您所見,每個團隊都屬于一個城市。所以我的問題是如何從附屬團隊中獲取不同城市的列表
1 回答
www說
TA貢獻1775條經驗 獲得超8個贊
這取決于你想要達到什么,但是例如
$this->attachedHotels->groupBy('city_id');https://laravel.com/docs/6.x/collections#method-groupby
或者
$this->attachedHotels->pluck('city_id')->unique();https://laravel.com/docs/6.x/collections#method-pluck
https://laravel.com/docs/6.x/collections#method-unique
- 1 回答
- 0 關注
- 116 瀏覽
添加回答
舉報
0/150
提交
取消
