Skip to content

Conversation

alepeino
Copy link
Contributor

This brings the method in line with Illuminate\Database\Concerns\BuildsQueries::when, and avoids the need for a use statement when we want the truthy value inside the callback.

For instance:

$item = $items->next();
$collection->when($item, function ($collection) use ($item) {
    return $collection->push($item);
});

can become

$collection->when($items->next(), function ($collection, $item) {
    return $collection->push($item);
});

@taylorotwell taylorotwell merged commit 3956865 into laravel:5.5 Nov 27, 2017
@GrahamCampbell GrahamCampbell changed the title Pass test value to Collection::when callbacks [5.5] Pass test value to Collection::when callbacks Nov 27, 2017
@alepeino alepeino deleted the collection-when-parameter branch November 28, 2017 03:39
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