Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel雄辩的查询关系_Php_Mysql_Laravel_Orm_Eloquent - Fatal编程技术网

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');
}