Skip to content
Snippets Groups Projects

3395883-Implement the whereNotIn method for Collection class

1 file
+ 19
0
Compare changes
  • Side-by-side
  • Inline
+ 19
0
@@ -74,4 +74,23 @@ class Collection extends BaseCollection {
};
}
/**
* Filter items where the value of a given key is not within the given values.
*
* @param string $key
* @param mixed $values
* @param bool $strict
* @return \Drupal\fluent\Collection
*/
public function whereNotIn($key, $values, $strict = false)
{
return $this->filter(function ($item) use ($key, $values, $strict) {
if ($item instanceof ContentEntityInterface) {
return !in_array(using($item)->value($key), $values, $strict);
} else {
return !in_array(data_get($item, $key), $values, $strict);
}
});
}
}
Loading