Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Higher Order Array or Object Bug Fix #16274

Merged
merged 4 commits into from
Nov 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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