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

Commit

Permalink
Laravel 5.4.27 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Jun 15, 2017
1 parent eb22dc7 commit 16a16f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ public function diff($items)
return new static(array_diff($this->items, $this->getArrayableItems($items)));
}

/**
* Get the items in the collection whose keys and values are not present in the given items.
*
* @param mixed $items
* @return static
*/
public function diffAssoc($items)
{
return new static(array_diff_assoc($this->items, $this->getArrayableItems($items)));
}

/**
* Get the items in the collection whose keys are not present in the given items.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ public function testDiffKeys()
$this->assertEquals(['first_word' => 'Hello'], $c1->diffKeys($c2)->all());
}

public function testDiffAssoc()
{
$c1 = new Collection(['id' => 1, 'first_word' => 'Hello', 'not_affected' => 'value']);
$c2 = new Collection(['id' => 123, 'foo_bar' => 'Hello', 'not_affected' => 'value']);
$this->assertEquals(['id' => 1, 'first_word' => 'Hello'], $c1->diffAssoc($c2)->all());
}

public function testEach()
{
$c = new Collection($original = [1, 2, 'foo' => 'bar', 'bam' => 'baz']);
Expand Down

0 comments on commit 16a16f2

Please sign in to comment.