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
projectswhere (select count() fromgroupsinner joinproject_groupongroups.id=project_group.group_idwhereproject_group.project_id=projects.idanduser_id= 1 andproject_id= 1 limit 10 offset 10) >= 1 and (select count() fromcommentsinner joinproject_commentoncomments.id=project_comment.comment_idwhereproject_comment.project_id=projects.idandproject_id= 1 andorder= 0 order bycomment.iddesc limit 10 offset 10) >= 1
If I remove offset it will just take fist 10 posts....
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire