framework: [5.6.27] Pagination pages count incorrect
- Laravel Version: 5.6.27
- PHP Version: 7.1.11
- Database Driver & Version: MariaDB 10
Description:
Pagination returns an incorrect number of pages. Eloquent collection has 32 items ( dd($collection->get()) and dd(count($collection->get())) show it). But when I use $collection->paginate(10) in back and $collection->links() in front it shows 24 pages. $collection->paginate(10)->count() return 234.
When I use simplePaginate method - it works fine.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (6 by maintainers)
paginate()doesn’t supportdistinct(). UsegroupBy()instead:Since you are using MariaDB, you have to add all columns from
select()togroupBy().I have faced same issue having next configuration:
Pagination provide empty pages when is used with join and distinct. My query is someting like
The problem is at this line https://github.com/laravel/framework/blob/5.6/src/Illuminate/Database/Eloquent/Builder.php#L710. Instead of:
should be:
This issue was fixed already for Database/Query/Builder https://github.com/laravel/framework/blob/5.6/src/Illuminate/Database/Query/Builder.php#L1980.
I have fixed this for my project creating Custom Eloquent Builder
and in my model I have added: