Skip to content

Conversation

sebj54
Copy link
Contributor

@sebj54 sebj54 commented Sep 23, 2024

Hi there!

I just a made a small PR to add a new $totalResults parameter to the jsonPaginate method so it can be passed to the Builder::paginate method.

This parameter has been added recently with this PR and its goal is to bypass the counting of total results (for performance mainly, see the PR for more info).

Actually I had to use this because I have a query using the DISTINCT keyword and the count I get from Builder::paginate is incorrect. There are a ton of issues on this subject and I don't think it will be fixed anytime soon because of the complexity.

Feel free to ask if anything should be changed or added :)

@sebj54 sebj54 changed the title Update usage docs Add $totalResults parameter + update docs Sep 24, 2024
@freekmurze
Copy link
Member

Could you add test to make sure that this behavior is working correctly?

@sebj54
Copy link
Contributor Author

sebj54 commented Dec 11, 2024

Yes, sure! Is a basic test like the one following in BuilderTest ok or I should I add more tests?

it('can return the specified total') ->expect(fn () => TestModel::jsonPaginate(15, null, 70)) ->toHaveCount(15) // assert that total is 70 // assert that there are 5 pages
@freekmurze freekmurze merged commit aaee592 into spatie:main Dec 16, 2024
@freekmurze
Copy link
Member

Thanks!

@francoisauclair911
Copy link

@freekmurze This has introduced a bug for laravel 10.x apps
#81

@freekmurze
Copy link
Member

@sebj54 could you take a look at this and PR a fix?

@sebj54
Copy link
Contributor Author

sebj54 commented Dec 20, 2024

@freekmurze Yes, sure. Actually, the reproduction project is not working properly on my side. I can only add a hard check before calling ->{$paginationMethod}.

What do you think about it? Also, if you have a recommended way to check Laravel's version, it would help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants