Skip to content

Conversation

@tautvydasr
Copy link
Contributor

Recently I faced a problem with collection pagination because it calculates negative offset and returns entries from the end of collection items.

For example:

$c = new Collection(['one', 'two', 'three', 'four']);
$c->forPage(0, 2)->all() // returns ['three', 'four']

I believe it would be nice if offset could not be negative and only positive numbers could be accepted as page.

@taylorotwell
Copy link
Member

Send to 5.5 branch.

@tautvydasr tautvydasr changed the base branch from master to 5.5 October 12, 2017 20:25
@sisve
Copy link
Contributor

sisve commented Oct 13, 2017

@tautvydasr This break other applications that rely on this behavior, Most things in PHP has the ability to use negative values to start at "the other end", like substr with a negative start value will count from the end of the string.

@deleugpn
Copy link
Contributor

@sisve looks like Taylor wanted this on point release.

@tautvydasr tautvydasr deleted the patch-collection-pagination branch October 13, 2017 15:44
@tautvydasr
Copy link
Contributor Author

@taylorotwell moved to 5.5 branch #21658

@sisve PHP ability to use negative values to start at "the other end" should be used with slice method which is using native function array_slice and this behavior is expected. Method forPage is supposed to only paginate collection items so negative offset behavior is not expected. I don't think there is a real world example where page number is supposed to be for instance -2.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants