我需要获取project_group.admin_id'
等于当前用户ID的所有项目。
此find
方法只返回一个项目:
$projects = Group::find(1) -> projects()->where('project_group.admin_id', '=',Auth::user()->id)->get();
有什么理由解决这个问题吗?
答案 0 :(得分:0)
正确答案:
public function userProjects(){
$adminIdCondition = function($q){
$q->where('admin_id', Auth::user()->admin_id);
};
$projects = Project::with(['groups' => $adminIdCondition])
->whereHas('groups', $adminIdCondition)
->get();
return $projects;
}