抵消不与Laravel关系[Laravel 5]

时间:2015-09-23 13:35:07

标签: php mysql laravel laravel-5

我试图跳过并采取元素......这是我的尝试:

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上的内部联接groupsid =   project_groupgroup_id其中project_groupproject_id =   projectsiduser_id = 1且project_id = 1限制10偏移   10)> = 1和(从comments内连接中选择计数()   project_comment上的commentsid = project_commentcomment_id   其中project_commentproject_id = projectsid和   project_id = 1和order = 0订单commentid desc limit 10   偏移10)> = 1

如果我删除offset,它只需要10个帖子....

0 个答案:

没有答案