我试图跳过并采取元素......这是我的尝试:
public function orderWhat($what){
$this->what = $what;
//QUERY FOR GROUPS AND PRODJECT_GROUP
$userCondition = function($q){
$q->where('user_id',Auth::id())->where('project_id',$this->id)->take(10)->skip(10);
};
//QUERY FOR COMMENTS AND PROJECT_COMMENT
$commentsCondition = function($q){
$q->where('project_id',$this->id)->where('order',$this->what)->orderBy('comment.id', 'DESC')->take(10)->skip(10);
};
$limit = function($q){
$q->take(10);
};
//RETURN PROJECT WITH COMMENTS
$results = Project::with(['comments' => $commentsCondition,'groups' => $userCondition])
->whereHas('groups', $userCondition)
->whereHas('comments', $commentsCondition)
->get();
return $results;
}
这将导致此查询,但我不会得到任何结果......
SQL:从
projects
中选择*其中(从groups
中选择计数()project_group
上的内部联接groups
。id
=project_group
。group_id
其中project_group
。project_id
=projects
。id
和user_id
= 1且project_id
= 1限制10偏移 10)> = 1和(从comments
内连接中选择计数()project_comment
上的comments
。id
=project_comment
。comment_id
其中project_comment
。project_id
=projects
。id
和project_id
= 1和order
= 0订单comment
。id
desc limit 10 偏移10)> = 1
如果我删除offset
,它只需要10个帖子....