I have users table which has a hasOne relationship with vendordetails table.
class User extends Authenticatable
{
public function vendor_details() {
return $this->hasOne('App\Vendordetail');
}
}
On the other side vendordetails table contains country_id, state_id and city_id and has relationship of belongsTo with Country, State and City model.
Vendordetail.php model is:-
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');
}
}
How can i fetch records of country, state and city if i query on users table.
$user = User::with('vendor_details')->first();
In this query it only finds the result of vendordetails table, i also wants country, state and city.
Thanks