Today, We will tell you about how to get or select last row from the table in Laravel. Laravel is a PHP framework. it provides many eloquent method library such as first(), latest() and orderBy(). let’s see that talking about how to select or get the last row from the table.
Generally, When we need to check the login credentials to the table at that time we have been used that. There are several ways to get or select a row from the table. here we are using first(), latest() and oderBy methods to select a row from the table.
Using The latest() Method
The latest() method get the latest row of the created_at date wise from the table.
$lastrow = DB::table('students')->latest()->first();
You can pass the table field id into the latest() method and get the last row.
$lastrow = DB::table('students')->latest('id')->first();
Using The orderBy Method
here below example in we will get the latest row using the orderBy descending order with the first() method.
$lastrow = DB::table('students')->orderBy('id', 'DESC')->first();
Youre so cool! I dont suppose Ive read anything like this before. So good to seek out any person with some authentic thoughts on this subject. realy thanks for starting this up. this web site is something that is needed on the web, someone with a little bit originality. helpful job for bringing one thing new to the internet!
Outstanding post, you have pointed out some superb points, I too conceive this s a very good website.
It’s really a nice and helpful piece of information. I am glad that you shared this useful information with us. Please keep us up to date like this. Thanks for sharing.