0

我正在尝试skip and take在 Laravel 5 中使用功能...当我只使用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()它时,它只返回空白页而没有错误。

4

1 回答 1

1

第一的:

您缺少一个“>”

$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;
}
于 2015-09-23T14:52:07.467 回答