How to Get Last Record in Laravel Eloquent?
Sep 18, 2019
Hi Guys,
In this tutorial, we will go over the demonstration of laravel get last record from database. step by step explain get last record in laravel eloquent. let’s discuss about get last record in mysql laravel . This post will give you a simple example of get last record in laravel .
There are several way to get last record from table in Laravel.
In PHP, you normally use order by clause with descending order to get last one record from database table and same you can do in laravel but laravel has some awesome method to interact with database table.
You can use latest method to get last record from database table in Laravel application.
Method 1:
$lastRecord = User::latest()->first();
dd($lastRecord);
Method 2:
$lastRecord = User::orderBy('id', 'DESC')->first();
dd($lastRecord);
It will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial