Posted inTechnology / Laravel / php / Programming

How to get last record of database table in Laravel?

Today, We want to share with you How to get last record of database table in Laravel?.In this post we will show you laravel 6 get last record example, hear for get last record laravel 6 we will give you demo and example for implement.In this post, we will learn about Get the last record from database table with an example.

How to get last record of database table in Laravel?

There are the Following The simple About How to Fetch last record of database table in Laravel6? Full Information With Example and source code.

As I will cover this Post with live Working example to develop Get the last record from database table, so the some major files and Directory structures for this example is following below.

Using latest() belong to created_at field:

$product_last = DB::table('products')->latest()->first();

Using orderBy() belong to id field:

$product_last2 = DB::table('products')->orderBy('id', 'DESC')->first();

Using latest() belong to id field:

$product_last3 = DB::table('products')->latest('id')->first();

Select Last Row in the Table

return DB::table('products')->latest('updated_at')->first();

using DB Object

DB::table('products')->get()->last();

To Retrive last record details

Product ::all()->last(); or
Product ::orderBy('id', 'desc')->first();

To Retrive last record id

Product::all()->last()->id; or
Product ::orderBy('id', 'desc')->first()->id;

Use the latest scope provided by Laravel out of the box.

Product::latest()->first();
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel 6 latest first example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype