Laravel Get Last/Latest Record Example

Get latest or last record from database in laravel app; Through this tutorial, you will learn how to get/fetch 5, 10, 20 latest or last record/data from database in laravel apps.

Laravel Get Last/Latest Record Example

There are two methods available in laravel eloquent to fetch/get 5, 10, 20, etc, latest or last record from database in laravel apps:

  • Get Last/Latest Record using Latest() Method
    • get latest 5 records laravel
    • get latest 10 records laravel
  • Get Last/Latest Record using Order_By() Method

Get Last/Latest Record using Latest() Method

Let’s see the laravel eloquent lastest() method to get/fetch data from database; is as follows:

get latest 5 records laravel

Using latest() method, you can get latest/last 5 records from database in laravel; is as follow:

Post::latest()->take(5)->get();

get latest 10 records laravel

Using latest() method, you can get latest/last 10 records from database in laravel; is as follow:

Post::latest()->take(10)->get();

Get Last/Latest Record using Order_By() Method

Let’s see the laravel eloquent order_by() method to get/fetch data from database; is as follows:

return DB::table('post')->order_by('id', 'desc')->first();

Conclusion

Through this tutorial, you have learned how to get/fetch 5, 10, 20 latest or last record/data from database in laravel apps.

Recommended Laravel Tutorials

Recommended:-Laravel Try Catch

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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