How to Get Last Record in Laravel Eloquent?

Sep 18, 2019

.

Admin

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....

#Laravel

#PHP

#Laravel 6