Мне нужно получить страны как groupBy
. К сожалению, это не работает.
Контроллер
public function create()
{
$tender_id = TenderMaster::select('id')->with('Ports')->get();
return $tender_id;
}
Модель отношений
public function Ports()
{
return $this->belongsToMany('App\Tender_Module\Masters\Air\AirPortCode','hmsc_bid_origin_port_comm','bid_id','port_id')->select('id','ap_city','ap_country');
}
Результат
[{"id": 213,"ports": [{"id": 52, "ap_city": "ALLENTOWN, PA", "ap_country": "Соединенные Штаты Америки", "pivot": {"bid_id": 213, "port_id": 52}}, {"id": 922, "ap_city": "MACON, GA", "ap_country": "Соединенные Штаты Америки", "pivot": {"bid_id": 213, "port_id": 922}}, {"id": 903, "ap_city": "LUBBOCK, TX", "ap_country": "Соединенные Штаты Америки", "pivot": {"bid_id": 213, "port_id": 903}}, {"id": 800, "ap_city": "Кусиро", "ap_country": "Япония", "стержень": { "bid_id": 213, "port_id": 800}}, { "идентификатор": 917, "ap_city":»MAASTRICHT / AACHEN "," ap_country ":" NETHERLANDS "," pivot ": {" bid_id ": 213," port_id ": 917}}]}]