通过自定义数据透视表(related_teams)在同一模型(团队模型)上具有一个EmiratesToMany关系
我的关系如下所示
现在附加和分离工作正常,但是如您所见,每个团队都属于一个城市 。 所以我的问题是如何从那些附属团队中获取不同城市的列表
答案 0 :(得分:0)
这取决于您要达到的目标,例如
$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