April 2015
Beginner
144 pages
3h 13m
English
Historically, other frameworks that have shipped with their own ORMs and query builders have returned result sets as either multidimensional arrays or Plain Old PHP Objects (POPOs). Eloquent has taken its cue from other, more mature ORMs and instead returns result sets as an instance of a collection object.
The collection object is powerful as it not only contains the data returned from the database, but also many helper methods, allowing you to manipulate that data before displaying it to the user.
If you need to find out whether a particular key exists in a collection, you can use the contains method:
$users = User::all();
if ($users->contains($userId))
{
// Do something
}When querying models, ...
Read now
Unlock full access