diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index b7ba7ab9bc04..aaadb774c9a8 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -649,7 +649,7 @@ public function max($callback = null) { $callback = $this->valueRetriever($callback); - return $this->reduce(function ($result, $item) use ($callback) { + return $this->filter()->reduce(function ($result, $item) use ($callback) { $value = $callback($item); return is_null($result) || $value > $result ? $value : $result; @@ -699,7 +699,7 @@ public function min($callback = null) { $callback = $this->valueRetriever($callback); - return $this->reduce(function ($result, $item) use ($callback) { + return $this->filter()->reduce(function ($result, $item) use ($callback) { $value = $callback($item); return is_null($result) || $value < $result ? $value : $result; diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 77553483f474..92d53f0d73c5 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1374,6 +1374,9 @@ public function testGettingMinItemsFromCollection() $c = new Collection([1, 2, 3, 4, 5]); $this->assertEquals(1, $c->min()); + $c = new Collection([1, null, 3, 4, 5]); + $this->assertEquals(1, $c->min()); + $c = new Collection(); $this->assertNull($c->min()); }