How To Get Last N Records From DB In Laravel

Hello Artisan

In this laravel eloquent tips tutorial, i will show you how we can print last n records in laravel. Laravel get latest record is the todays topic. In this Laravel get latest record by date tutorial i will show you the query of how we can get last 10 records in laravel.

Laravel eloquent get last 10 records is the query of showing latest records. Sometimes in our blog we need to show latest post, popular post or featured post etc. In this tutorial i will show you how to get latest post or latest record in laravel with eloquent query.

Example code

Model::orderBy('id', 'desc')->take(5)->get();


Example code



or simply use this for your latest post or recent post

Model::orderBy('id', 'desc')->limit(5)->get();


Recommended : How to Get Second Last Record in Laravel


Hope it can help you.


#laravel #laravel-7 #eloquent-tips