Skip() 函数不工作 [Laravel 5]
Skip() function not working [Laravel 5]
我正在尝试在 Laravel 5 中使用 skip and take
函数...当我只使用 take()
时它会找到,但如果我添加 skip()
它不会...
这是我的代码:
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)->skip(20)->take(20);
};
//QUERY FOR COMMENTS AND PROJECT_COMMENT
$commentsCondition = function($q){
$q->where('project_id',$this->id)->where('order',$this->what)->orderBy('comments.id', 'DESC')-skip(20)->take(20);
};
//RETURN PROJECT WITH COMMENTS
$results = Project::with(['comments' => $commentsCondition,'groups' => $userCondition])
->whereHas('groups', $userCondition)
->whereHas('comments', $commentsCondition)
->get();
return $results;
}
当我添加 skip()
时,它只是 return 没有错误的空白页。
第一个:
你少了一个“>”
$q->where('project_id',$this->id)->where('order',$this->what)->orderBy('comments.id', 'DESC')-skip(20)->take(20);
结果:
public function orderWhat($what){
$this->what = $what;
$result = Project::with(['comments' => function($q) {
$q->where('project_id',$this->id)->where('order',$this->what)
->skip(20)->take(20);
}, 'groups' => function($q) {
$q->where('user_id',Auth::id())->where('project_id',$this->id)->skip(20)->take(20);
}])->get();
return $results;
}
我正在尝试在 Laravel 5 中使用 skip and take
函数...当我只使用 take()
时它会找到,但如果我添加 skip()
它不会...
这是我的代码:
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)->skip(20)->take(20);
};
//QUERY FOR COMMENTS AND PROJECT_COMMENT
$commentsCondition = function($q){
$q->where('project_id',$this->id)->where('order',$this->what)->orderBy('comments.id', 'DESC')-skip(20)->take(20);
};
//RETURN PROJECT WITH COMMENTS
$results = Project::with(['comments' => $commentsCondition,'groups' => $userCondition])
->whereHas('groups', $userCondition)
->whereHas('comments', $commentsCondition)
->get();
return $results;
}
当我添加 skip()
时,它只是 return 没有错误的空白页。
第一个:
你少了一个“>”
$q->where('project_id',$this->id)->where('order',$this->what)->orderBy('comments.id', 'DESC')-skip(20)->take(20);
结果:
public function orderWhat($what){
$this->what = $what;
$result = Project::with(['comments' => function($q) {
$q->where('project_id',$this->id)->where('order',$this->what)
->skip(20)->take(20);
}, 'groups' => function($q) {
$q->where('user_id',Auth::id())->where('project_id',$this->id)->skip(20)->take(20);
}])->get();
return $results;
}