Code: Getting multiple specific Laravel models

I had a case where I had an array of model ids, and I wanted to return a collection of these models. That is I had a list of model ids, but it appeared no nice way to get all of them at once. However from the 4.2 API docs you can see that the find() should be able to return either a Model, or a Collection of models.


Naturally to get one model just use:
User::find( $id );
You could loop over the ::find() to pull each one manually, but that will result in multiple unnecessary queries to the database right? Who wants that?

Find() with Array

Here is a quite simple approach that Eloquent supports that seems quite obvious after you see it. You can just pass an array of model ids right to the find() function!

$arr = array($id1, $id2, $id3);
User::find( $arr );

This will return a collection of models just as you would expect, no fussing around with loops.  A simple way to get Multiple Specific Laravel Models by Id.