laravel/framework — pull request #6502 by JosephSilber (2014-11-26 15:17:48+00:00)
Title: Add where method to collection

Adds a `where` method to the `Collection` class, to be used similarly to the `where` method on the query builder:

```php
$collection = new Collection(['v' => 1], ['v' => 2], ['v' => 3]);

$underThree = $collection->where('v', '<', 3);
```

---

This is quite useful as is. If we add Eloquent support to `data_get` (which we should anyhow do, for many other reasons) this would become infinitely more useful:

```php
$users = User::all();

$adults = $users->where('age', '>=', 18);

$kids = $users->where('age', '<', 18);
```

Where before this required either two separate queries, or 2 more-verbose `filter` calls.

---

PS Shout-out to the [Cartalyst](https://cartalyst.com/) team. I got the operator switch idea from their excellent [Conditions package](https://cartalyst.com/manual/conditions/).