0
我有四個表如何使用此關係設置從另一個表中獲取數據?
市
id
city
state_id
國家
id
name
City_Vendor
id
vendor_id
city_id
供應商
id
name
現在,如果我這樣做,我得到了城市和STATE_ID但不是國家名稱
Vendor::with('cities')->get();
這是我做得到的狀態在我看來,這是不理想..
<?php foreach($vendor['cities'] as $state): ?>
@if($state['state_id'] == $city['state_id'])
{{$state['state']['state']}}
<?php break; ?>
@endif
<?php endforeach;?>
我想獲取州名也不只是state_id。要做到這一點,最好的方法是什麼?