illuminate/database — pull request #25 by franzliedke (2012-10-12 22:28:13+00:00)
Title: Collection::contains()

This rather large pull request implements a `contains()` method for the collection class.

That method checks whether an element with the given primary key (ID) is part of the collection.
To make this simpler, I made sure that every item in the collection is indexed by the ID. That makes up the largest part of this pull request (along with modifying the unit tests appropriately).

### Example

What does that allow us to do?

For example, if you have a user with a bunch of associated rules, it allows you to easily check whether your user is associated with the rule with ID 5 like this:

if ($user->roles->contains(1))
{
// do something...
}

### Notes & questions for Taylor

I am, let's say, 90-percent sure that this implementation is fine (tested, after all). I doubt there is a central place where this could be done, except for the collection constructor maybe, but I didn't want to add any ugly `instanceof`-like code (meta programming etc.). I usually found a place to set the keys in a place where the arrays were being assembled anyway, because I tried to avoid having to iterate over all the elements just for this purpose.

Also, about testing: the feature is basically implicitly tested in the existing tests now because they rely on certain IDs being returned as keys, but I wonder whether I should add methods testing explicitly this...