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.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

Snippet Contents

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


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.


Web Programming Tutorials Example with Demo

Read :


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 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.

Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Laravel Add Days Hours Minutes To Datetime
  2.   Simple Ecommerce Shopping Cart PHP mysql
  3.   C# Linq Left Outer Join using LINQ To SQL Tutorial
  4.   How To Configure Supervisor For Laravel 5/6/7 Queue Jobs?
  5.   Directives in Vue.js Examples - vue interface
  6.   Laravel 5/6/7 Carbon date format Example
  7.   Laravel 6 Inner Join Query Example - MySQL
  8.   Remove particular value from jquery Array
  9.   10 Useful PHP Filesystem Functions with Example
  10.   Laravel sending email via gmail smtp server Setup configuration

Leave a Reply

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