Skip to content

Commit

Permalink
[5.4] Higher Order Array or Object Bug Fix (#16274)
Browse files Browse the repository at this point in the history
* Array or Object

* Array or Object

* Improve array or object
  • Loading branch information
alexbowers authored and taylorotwell committed Nov 6, 2016
1 parent ee385fa commit 6c38ec5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/HigherOrderCollectionProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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};
});
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c38ec5

Please sign in to comment.