Laravel pagination not working with group by clause

前端 未结 5 463
北荒
北荒 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:42

    This works for me in laravel 5.2

    Select(\DB::RAW("assignment_descendant_child.assignment_descendant_child_id, assignment_descendant_child.assignment_descendant_child_name, COUNT(assignment_descendant.assignment_descendant_id) as xNum"))
                ->leftJoin(
                    'assignment_descendant',
                    'assignment_descendant.assignment_descendant_child_id',
                    '=',
                    'assignment_descendant_child.assignment_descendant_child_id'
                )
                ->orderBy('assignment_descendant_child_name')
                ->groupBy('assignment_descendant_child.assignment_descendant_child_id')
                ->paginate(\Config::get('constants.paginate_org_index'))
    

提交回复
热议问题