Laravel pagination not working with group by clause

前端 未结 5 466
北荒
北荒 2020-12-19 04:36

It seems Laravel pagination deos not working properly with group by clause. For example:

            $users = Subject::select(DB::raw(\'subjects.*, count(user_sub         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 05:29

    I think this works if you want to group by and paginate.

    $code = DB::table('sources')
    ->select(DB::raw('sources.id_code,sources.title,avg(point) point'))
    ->join('rating','sources.id_code','rating.id_code')
    ->groupBy('sources.id_code')
    ->groupBy('sources.title')
    ->groupBy('sources.language')
    ->groupBy('sources.visited')
    ->groupBy('sources.')
    ->paginate(5);
    

提交回复
热议问题