How To Get Last Row Of Database Table In Laravel

Sometimes we need to require to get only last record of table in our project, We can fetch it in several ways. We can fetch last record of database table using latest() or orderBy(). In bellow example. In this example you can see how i get the last record of table.

In this quick example of laravel get last record from collection i will show you three ways. You can choose one of them to use. If you don't know the query of Laravel get latest record by date, then just see the below code.

Example One

return \App\Customer::orderBy('id', 'desc')->first();


Example Two



Example Three



Hope it can help you. 


#laravel #laravel-7 #eloquent-tips