The method where()
allows users to filter collection items given a key-value pair. This method filters items by checking whether the $key
has some value equal to provided $value
.
You can also pass a parameter to control how method compares $key
with $value
. Laravel runs the given command and returns a new collection of instances containing filtered items that satisfied the condition.
Illuminate\Support\Collection class provides an easy, accessible wrapper for working with arrays of data.
/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $operator
* @param mixed $value
* @return static
*/
public function where($key, $operator = null, $value = null)
{
...
}
#tutorials #where() #laravel