I am trying to take skip and take elements... Here is my try:
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;
}
This will result with this query, but I will not get any result...
SQL: select * from
projects
where (select count() fromgroups
inner joinproject_group
ongroups
.id
=project_group
.group_id
whereproject_group
.project_id
=projects
.id
anduser_id
= 1 andproject_id
= 1 limit 10 offset 10) >= 1 and (select count() fromcomments
inner joinproject_comment
oncomments
.id
=project_comment
.comment_id
whereproject_comment
.project_id
=projects
.id
andproject_id
= 1 andorder
= 0 order bycomment
.id
desc limit 10 offset 10) >= 1
If I remove offset
it will just take fist 10 posts....