Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Laravel 5.3.20 changes (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Oct 25, 2016
1 parent 321ff9a commit 07547aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,13 @@ public function keyBy($keyBy)
$results = [];

foreach ($this->items as $key => $item) {
$results[$keyBy($item, $key)] = $item;
$resolvedKey = $keyBy($item, $key);

if (is_object($resolvedKey)) {
$resolvedKey = (string) $resolvedKey;
}

$results[$resolvedKey] = $item;
}

return new static($results);
Expand Down Expand Up @@ -698,6 +704,10 @@ public function min($callback = null)
*/
public function only($keys)
{
if (is_null($keys)) {
return new static($this->items);
}

$keys = is_array($keys) ? $keys : func_get_args();

return new static(Arr::only($this->items, $keys));
Expand Down
1 change: 1 addition & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ public function testOnly()
{
$data = new Collection(['first' => 'Taylor', 'last' => 'Otwell', 'email' => '[email protected]']);

$this->assertEquals($data->all(), $data->only(null)->all());
$this->assertEquals(['first' => 'Taylor'], $data->only(['first', 'missing'])->all());
$this->assertEquals(['first' => 'Taylor'], $data->only('first', 'missing')->all());

Expand Down

0 comments on commit 07547aa

Please sign in to comment.