diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 4d7692dd650b..ac0f501c7252 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -433,9 +433,9 @@ public function filter(callable $callback = null) public function when($value, callable $callback, callable $default = null) { if ($value) { - return $callback($this); + return $callback($this, $value); } elseif ($default) { - return $default($this); + return $default($this, $value); } return $this; diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 418e8a728278..b6babaf92bc0 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -2306,8 +2306,8 @@ public function testWhen() { $collection = new Collection(['michael', 'tom']); - $collection->when(true, function ($collection) { - return $collection->push('adam'); + $collection->when('adam', function ($collection, $newName) { + return $collection->push($newName); }); $this->assertSame(['michael', 'tom', 'adam'], $collection->toArray());