Here, I will show you how to get the last record from the database in Laravel. you can simply get the last record using the Laravel built-in eloquent model.
There are several ways to get the last record from the table in Laravel.
In PHP, you normally use order by clause with descending order to get the last one record from the database table, and the same you can do in laravel but laravel has some awesome methods to interact with a database table.
You can use the latest method to get the last record from the database table in the Laravel application.
$lastRecord = User::latest()->first(); print_r($lastRecord);
$lastRecord = User::orderBy('id', 'DESC')->first(); print_r($lastRecord);
Thank you for following us and please drop a comment if it’s solved your problem and you learn something new. Thank you and have a great day ahead.