Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make page number available in chunk closure #19316

Merged
merged 2 commits into from
May 24, 2017

Conversation

gjreasoner
Copy link
Contributor

I've run into a scenario where it would be really nice to have the page number available in a chunk closure; perhaps it could be accomplished another way and I'd love to hear feedback.

I'm using chunk to round up users by their estimated points and assign a rank back to them like this;

User::orderBy('estimated_points', 'desc')->chunk(100,function($users,$page){

    foreach ($users as $key => $user) {
        $user->rank = (101*($page-1)) + ($key + 1);
        $user->save();
    }

});

I've roughly tested to make sure that the closure works fine without the second parameter on php 7.1 but I'm not sure other versions or scenarios and I'd be open to writing a test to ensure this functionality.

Thanks for your consideration.

@taylorotwell taylorotwell merged commit 609d1e2 into laravel:master May 24, 2017
@gjreasoner gjreasoner deleted the patch-1 branch October 4, 2017 16:14
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.

2 participants