Fix pagination when using distinct() in Query or Eloquent

Pagination works correcty when using groupBy(), but not when distinct() is used. I think this patch fixes this issue, but please have a good look at it as I don't know the ins and outs of L4.

I realize it's still not a very efficient solution, but this fixes behaviour when using distinct(). Better a slow result that a wrong result. A solution using SQL_CALC_FOUND_ROWS or similar is preferred.