From 2c942222f37f05cd53e0edadcd22b98f4974272c Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Sat, 5 Nov 2016 00:26:42 +0000 Subject: [PATCH 1/3] Array or Object --- src/Illuminate/Support/HigherOrderCollectionProxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/HigherOrderCollectionProxy.php b/src/Illuminate/Support/HigherOrderCollectionProxy.php index f5c7dcba368d..bc0d7d11e98c 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 data_get($value, $key); }); } From 752dd70d2d772347b0d134dca7af357bc83d09fb Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Sat, 5 Nov 2016 00:26:42 +0000 Subject: [PATCH 2/3] 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..bc0d7d11e98c 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 data_get($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 From d5d3d6fbcbc1e630d1ce455c379c8cd5097a2c7a Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Sat, 5 Nov 2016 19:41:38 +0000 Subject: [PATCH 3/3] Improve array or object --- src/Illuminate/Support/HigherOrderCollectionProxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/HigherOrderCollectionProxy.php b/src/Illuminate/Support/HigherOrderCollectionProxy.php index bc0d7d11e98c..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 data_get($value, $key); + return is_array($value) ? $value[$key] : $value->{$key}; }); }