Skip to content

Commit 3956865

Browse files
alepeinotaylorotwell
authored andcommitted
Pass test value to Collection::when callbacks (#22224)
1 parent cfcbad9 commit 3956865

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Illuminate/Support/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ public function filter(callable $callback = null)
433433
public function when($value, callable $callback, callable $default = null)
434434
{
435435
if ($value) {
436-
return $callback($this);
436+
return $callback($this, $value);
437437
} elseif ($default) {
438-
return $default($this);
438+
return $default($this, $value);
439439
}
440440

441441
return $this;

tests/Support/SupportCollectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,8 +2306,8 @@ public function testWhen()
23062306
{
23072307
$collection = new Collection(['michael', 'tom']);
23082308

2309-
$collection->when(true, function ($collection) {
2310-
return $collection->push('adam');
2309+
$collection->when('adam', function ($collection, $newName) {
2310+
return $collection->push($newName);
23112311
});
23122312

23132313
$this->assertSame(['michael', 'tom', 'adam'], $collection->toArray());

0 commit comments

Comments
 (0)