我试图获取用户所在国家但不起作用,我的示例代码是:
用户模型:
public function countryName()
{
return $this->hasOne('App\Country');
}
Tables:
User:
- id;
- name;
- country_id;
Countries:
-id ;
- name;
答案 0 :(得分:2)
将关系设为:
<div class="show-for-small-only">
<div class="tableHomework2">
<a href="/homeworks/76">
<div class="teachers linkable">
<input type="checkbox" name="homework[id][]" id="homework_id_" value="76" class="narrowtr" />
<div class="progress-meter-interest-mobile horizTranslate" data-bar-length=" 60%">3</div>
<font size="1">High</font>  
<font size="1"><strong>25/11/2016</strong></font>
</div>
要让国家这样做:
public function country()
{
return $this->belongsTo('App\Country');
}