From 6c38ec5d1b58fc227a3698bdd674218549aeb9b6 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Sun, 6 Nov 2016 23:00:25 +0000 Subject: [PATCH] [5.4] Higher Order Array or Object Bug Fix (#16274) * Array or Object * Array or Object * Improve array or object --- .../Support/HigherOrderCollectionProxy.php | 2 +- tests/Support/SupportCollectionTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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