Eloquent致命错误:在第451行的\illumb\database\Eloquent\Builder.php中调用未定义的方法Eloquent\Collection::AddagerConstraints()
我下面介绍一个示例,您可以在一个表中保存关系,以确定一个用户是否是另一个用户的朋友,反之亦然 在我的例子中,我需要将绑定在一起的项目保存在一个关系表中 因此,在Project.php模型中,我创建了以下雄辩的关系:Eloquent致命错误:在第451行的\illumb\database\Eloquent\Builder.php中调用未定义的方法Eloquent\Collection::AddagerConstraints(),php,laravel,laravel-4,eloquent,Php,Laravel,Laravel 4,Eloquent,我下面介绍一个示例,您可以在一个表中保存关系,以确定一个用户是否是另一个用户的朋友,反之亦然 在我的例子中,我需要将绑定在一起的项目保存在一个关系表中 因此,在Project.php模型中,我创建了以下雄辩的关系: <?php /*** Bound together projects ***/ public function projectsBoundToThisOne(){ return $this->belongsToMany('Models\Us
<?php
/*** Bound together projects ***/
public function projectsBoundToThisOne(){
return $this->belongsToMany('Models\User\Project', 'boundTogether_projects', 'bound_id', 'project_id');
}
public function boundTo(){
return $this->belongsToMany('Models\User\Project', 'boundTogether_projects', 'project_id', 'bound_id');
}
public function boundTogetherProjects(){
return $this->projectsBoundToThisOne()->wherePivot('bound',true)->get()->merge($this->boundTo()->wherePivot('bound', true)->get());
}
雄辩的版本是5.1
我错过了什么?如何修复它?这可能是因为
boundTogetherProjects
不是关系方法。它简单地从合并到另一个的关系中获取一些数据。因此,有效的方法是:
$projects = Project::with('projectsBoundToThisOne','boundTo');
然后,对于每个项目,您可以运行boundTogetherProjects
来获取项目
$projects->each(function($project) {
dd($project->boundTogetherProjects());
});
这可能是因为
boundTogetherProjects
不是关系方法。它简单地从合并到另一个的关系中获取一些数据。因此,有效的方法是:
$projects = Project::with('projectsBoundToThisOne','boundTo');
然后,对于每个项目,您可以运行boundTogetherProjects
来获取项目
$projects->each(function($project) {
dd($project->boundTogetherProjects());
});