Php laravel雄辩的查询关系
我的表格结构如下: 简历Php laravel雄辩的查询关系,php,mysql,laravel,orm,eloquent,Php,Mysql,Laravel,Orm,Eloquent,我的表格结构如下: 简历 -id -... 教育 -id -简历id -学位id - 学位 -id -名字 我的简历模式如下: class Resume extends Eloquent { public function degree(){ return $this->hasManyThrough('Degree', 'Education', 'resume_id', 'degree_id'); } } public function degree() {
-id
-... 教育
-id
-简历id
-学位id
- 学位
-id
-名字 我的简历模式如下:
class Resume extends Eloquent {
public function degree(){
return $this->hasManyThrough('Degree', 'Education', 'resume_id', 'degree_id');
}
}
public function degree()
{
return $this->belongsToMany('Degree')->withPivot('resume_id');
}
形成的查询如下所示:
select `education`.*, `degrees`.`resume_id` from `education` inner join `degrees` on`degrees`.`id` = `education`.`degree_id` where `degrees`.`resume_id` = 36035
但我想要的是:where education.resume\u id=36035
或者有没有其他更好的方法来链接查询,这样我就可以直接从resume访问degree表,比如$resume->degree
我甚至尝试过快速加载方法,但无法通过链接检索数据我认为最好使用
belongTomany
可能是这样的:
class Resume extends Eloquent {
public function degree(){
return $this->hasManyThrough('Degree', 'Education', 'resume_id', 'degree_id');
}
}
public function degree()
{
return $this->belongsToMany('Degree')->withPivot('resume_id');
}