You never mentioned whether you use Eloquent, Laravel's default ORM or not. In case you want, say that you want to get the last record of the user table created by_at, you could probably do the following:
User::orderBy('created_at', 'desc')->first();
First, he orders a user named created_at, in descending order, and then takes the first record of the result.
This will return you an instance of the User object, not a collection. Of course, to use this alternative, you must have a User model extending the Eloquent class. This may seem a bit confusing, but itβs very easy to get started, and ORM can be really useful.
For more information, check out the official documentation, which is fairly rich and well detailed.
Luis Milanese Mar 24 '14 at 4:33 2014-03-24 04:33
source share