【发布时间】:2018-05-05 18:19:22
【问题描述】:
我还是 laravel 新手
我有以下表格
user
id
first_name
last_name
educations
id,
user_id //references user id
type
现在在我的user 模型中,我想获得一个特定的用户教育,可以是很多
所以一个用户可以拥有许多教育,但每个教育都属于一个用户。
所以在我的user 模型中,我有
public function education()
{
return $this->hasMany('App\ApplicantEducation','id','user_id');
}
在我的Education 模型中,我有
public function user()
{
return $this->belongsTo('App\User','user_id','id');
}
但上述失败,我无法检索 user 特定的educations
我哪里错了?
【问题讨论】: