Reputation: 1477
Im trying to get the user country but isnt working, my example code is:
User Model:
public function countryName()
{
return $this->hasOne('App\Country');
}
Tables:
User:
- id;
- name;
- country_id;
Countries:
-id ;
- name;
Upvotes: 1
Views: 458
Reputation: 163978
Set relation as:
public function country()
{
return $this->belongsTo('App\Country');
}
To get the country do this:
$user->country->name;
Upvotes: 2