【发布时间】:2015-09-23 12:46:45
【问题描述】:
我正在尝试在 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() 时,它只会返回空白页而不会出错。
【问题讨论】: