diff --git a/src/Illuminate/Support/HigherOrderCollectionProxy.php b/src/Illuminate/Support/HigherOrderCollectionProxy.php index f5c7dcba368d..f9024316e672 100644 --- a/src/Illuminate/Support/HigherOrderCollectionProxy.php +++ b/src/Illuminate/Support/HigherOrderCollectionProxy.php @@ -40,7 +40,7 @@ public function __construct(Collection $collection, $method) public function __get($key) { return $this->collection->{$this->method}(function ($value) use ($key) { - return $value->{$key}; + return is_array($value) ? $value[$key] : $value->{$key}; }); } diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 813f479f8fba..a3433a576383 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1654,6 +1654,20 @@ public function testHigherOrderCollectionMap() $this->assertEquals(['TAYLOR', 'TAYLOR'], $collection->each->uppercase()->map->name->toArray()); } + + public function testHigherOrderCollectionMapFromArrays() + { + $person1 = ['name' => 'Taylor']; + $person2 = ['name' => 'Yaz']; + + $collection = collect([$person1, $person2]); + + $this->assertEquals(['Taylor', 'Yaz'], $collection->map->name->toArray()); + + $collection = collect([new TestSupportCollectionHigherOrderItem, new TestSupportCollectionHigherOrderItem]); + + $this->assertEquals(['TAYLOR', 'TAYLOR'], $collection->each->uppercase()->map->name->toArray()); + } } class TestSupportCollectionHigherOrderItem