aarondfrancis / fast-paginate

A fast implementation of offset/limit pagination for Laravel.
MIT License
1.21k stars 56 forks source link

Count on pages is off by one from provided per_page #2

Closed joecampo closed 2 years ago

joecampo commented 2 years ago

Hey, sorry to ping you on this.

One thing I've run into is this line seems to cause the count on a page to be off-by-one.

So for instance, if there are 5 Post records, and I set per_page=5 I would expect that we'd get back all 5 on the same page, but what I'm actually seeing (below) is 4.

Removing the decrement on line 31 seems to resolve the issue, but I couldn't grok why it is necessary to do so before passing it to simplePaginate.

Apologies if I'm missing something obvious here.

image

aarondfrancis commented 2 years ago

Doh, you're absolutely right. I was watching the SQL not the output. Let me updated. Turns out I'm the one missing something obvious!

aarondfrancis commented 2 years ago

Making this a package, I think I fixed this!