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.14 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Mar 1, 2017
1 parent 976797a commit f2761d8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,35 @@ public function whereInStrict($key, $values)
return $this->whereIn($key, $values, true);
}

/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $values
* @param bool $strict
* @return static
*/
public function whereNotIn($key, $values, $strict = false)
{
$values = $this->getArrayableItems($values);

return $this->reject(function ($item) use ($key, $values, $strict) {
return in_array(data_get($item, $key), $values, $strict);
});
}

/**
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $values
* @return static
*/
public function whereNotInStrict($key, $values)
{
return $this->whereNotIn($key, $values, true);
}

/**
* Get the first item from the collection.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ public function testWhereInStrict()
$this->assertEquals([['v' => 1], ['v' => 3]], $c->whereInStrict('v', [1, 3])->values()->all());
}

public function testWhereNotIn()
{
$c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]);
$this->assertEquals([['v' => 2], ['v' => 4]], $c->whereNotIn('v', [1, 3])->values()->all());
}

public function testWhereNotInStrict()
{
$c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]);
$this->assertEquals([['v' => 2], ['v' => '3'], ['v' => 4]], $c->whereNotInStrict('v', [1, 3])->values()->all());
}

public function testValues()
{
$c = new Collection([['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']]);
Expand Down

0 comments on commit f2761d8

Please sign in to comment.