Skip to content

Commit

Permalink
[5.5] Collection as parameter on Collection::except (#22399)
Browse files Browse the repository at this point in the history
* Type collection as Collection::except parameter

* reformat

* Use method to get the Collection items

* Update Collection.php
  • Loading branch information
glorand authored and taylorotwell committed Dec 13, 2017
1 parent 2bad848 commit 18402a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,16 @@ public function every($key, $operator = null, $value = null)
/**
* Get all items except for those with the specified keys.
*
* @param mixed $keys
* @param \Illuminate\Support\Collection|mixed $keys
* @return static
*/
public function except($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
if ($keys instanceof Collection) {
$keys = $keys->keys()->all();
} elseif (! is_array($keys)) {
$keys = func_get_args();
}

return new static(Arr::except($this->items, $keys));
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,11 @@ public function testExcept()

$this->assertEquals(['first' => 'Taylor'], $data->except(['last', 'email', 'missing'])->all());
$this->assertEquals(['first' => 'Taylor'], $data->except('last', 'email', 'missing')->all());
$this->assertEquals(['first' => 'Taylor'], $data->except(collect(['last' => 'Otwell', 'email' => '[email protected]', 'missing']))->all());

$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->except(['last'])->all());
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->except('last')->all());
$this->assertEquals(['first' => 'Taylor', 'email' => '[email protected]'], $data->except(collect(['last' => 'Otwell']))->all());
}

public function testPluckWithArrayAndObjectValues()
Expand Down

0 comments on commit 18402a6

Please sign in to comment.