联盟延伸Eloquent {
protected $ table =‘lige’;
protected $ fillable = [‘league_id’,‘liga’,‘sport_id’];
public $ timestamps = true;
公共职能 MEC </跨度> (){ 返回$ this-&gt; hasMany(’匹配 正常,“lige”的子项嵌套在它们应该的位置,如此处的链接所示,但是,如果我尝试添加匹配,则如下所示:
$ mecevi = Sport :: with(‘liga.mec’) - &gt; get();
我得到一个“ MEC </跨度> “节点,这是
弄清楚了,在给出所有条件后,我的桌子关系都没了 return $this->hasMany('Comment', 'foreign_key', 'local_key'); 一切都开始发挥作用了。谢谢大家。
return $this->hasMany('Comment', 'foreign_key', 'local_key');
根据我的理解,你想得到所有的 matches 的 leagues
matches
leagues
问题可能出在第二个参数中 hasMany 功能
hasMany
public function mec(){ return $this->hasMany('Match', 'league_id'); }
第二个参数需要 foreign_key
foreign_key
public function mec(){ return $this->hasMany('Match', 'match_id', 'league_id'); }
资源: http://laravel.com/docs/4.2/eloquent#one-to-many