我有與vendordetails表hasOne關係的用戶表。Laravel雄辯的關係獲取記錄到第三級關係
class User extends Authenticatable
{
public function vendor_details() {
return $this->hasOne('App\Vendordetail');
}
}
另一方面vendordetails表包含COUNTRY_ID,STATE_ID和city_id,並與國家,州和城市模型屬於關聯關係。
Vendordetail.php模式是: -
class Vendordetail extends Model
{
public $timestamps = false;
public function this_country(){
return $this->belongsTo('App\Country', 'country_id');
}
public function this_state(){
return $this->belongsTo('App\Country', 'state_id');
}
public function this_city(){
return $this->belongsTo('App\Country', 'city_id');
}
}
我如何可以獲取的國家,州和城市的記錄,如果我的用戶表中查詢。
$user = User::with('vendor_details')->first();
在此查詢中,它只查找vendordetails表的結果,我也希望國家,州和城市。
感謝
嘗試類似$ USER =用戶::使用( 'vendor_details.othe_relationship') - >第一(); – Chintan7027