It seems Laravel pagination deos not working properly with group by clause. For example:
$users = Subject::select(DB::raw(\'subjects.*, count(user_sub
Check the documentation https://laravel.com/docs/5.2/pagination
Currently, pagination operations that use a
groupBystatement cannot be executed efficiently by Laravel. If you need to use agroupBywith a paginated result set, it is recommended that you query the database and create a paginator manually.