Thursday, January 31, 2019

How to get last record of table in Laravel 5.7?

No comments
Here, i will show you how to select last row of database table using Laravel query builder. In PHP Laravel framework, there are several eloquent method to get last record from table.
Hi Dear Friends,

In this post We would like to share infinity knowladge My Good experience and Best solution For .

Laravel Examples

Try this it will help you and for more information click here: Laravel Examples.
1)first()
2)orderBy()
3)latest()
Above three method through we can simply select last record of any table of database, here i gave you "posts" table for example. As bellow you can see first way using "order by".
Using Order By:

$lastRecord = DB::table('posts')->orderBy('id', 'DESC')->first();
now as bellow, i will get last record using latest() method:
Using latest method:
$lastRecord = DB::table('posts')->latest()->first();
As above example will help you to fetch last record of table.

 Read :

I hope you like this Post, Please feel free to comment below, your Any Idea, suggestion and problems if you face - I am here to Resolve your Any problems.
We hope it can help you...

No comments :

Post a Comment