title: Laravel pagination not working with group by clause
body: <p>It seems Laravel pagination does not working properly with group by clause. For example:</p>
  <pre><code>$users = Subject::select(DB::raw('subjects.*, count(user_subjects.id) as total_users'))
              -&gt;join('user_subjects', 'user_subjects.subject_id', '=', 'subjects.id')
              -&gt;whereNull('user_subjects.deleted_at')
              -&gt;groupBy('subjects.id')
              -&gt;orderBy('subjects.updated_at', 'desc')
              -&gt;paginate(25);
  </code></pre>
  <p><strong>Produced</strong></p>
  <pre><code>select subjects.*, count(user_subjects.id) as total_users 
  from `subjects` inner join `user_subjects` on `user_subjects`.`subject_id` = `subjects`.`id` 
  where `subjects`.`deleted_at` is null and `user_subjects`.`deleted_at` is null 
  group by `subjects`.`id` 
  order by `subjects`.`updated_at` desc
  </code></pre>
  <p>note that, there is no <code>limit</code> clause on the query.</p>
  <p><strong>Working fine if no group by clause in the query:</strong></p>
  <pre><code>$users = Subject::select(DB::raw('subjects.*, count(user_subjects.id) as total_users'))
              -&gt;join('user_subjects', 'user_subjects.subject_id', '=', 'subjects.id')
              -&gt;whereNull('user_subjects.deleted_at')
              -&gt;orderBy('subjects.updated_at', 'desc')
              -&gt;paginate(25);
  </code></pre>
  <p><strong>produced the following query:</strong></p>
  <pre><code>select subjects.*, count(user_subjects.id) as total_users from `subjects` 
  inner join `user_subjects` on `user_subjects`.`subject_id` = `subjects`.`id`
  where `subjects`.`deleted_at` is null and `user_subjects`.`deleted_at` is null 
  order by `subjects`.`updated_at` desc 
  limit 25 offset 0
  </code></pre>
  <p>does anyone has any idea how can i fix this?</p>