ホーム > Laravel > How to Get the Latest Data in Laravel (Take 5)
Laravel

How to Get the Latest Data in Laravel (Take 5)

Thank you for your continued support.
This article contains advertisements that help fund our operations.

⇨ Click here for the table of contents for Laravel articles

I summarized how to get the latest data in Laravel, taking 5 items.

Laravel Framework 8.83.8
Vue 2.6

Conclusion

// Get the latest 5 items from the posts table
$posts = Post::orderBy('id','desc')->take(5)->get();

Explanation

In this example, we retrieve the 5 latest items from the Posts table in order of the latest ID.

Descending order of id (retrieved from the largest ID)

orderBy('id','desc')

Get 5 items

take(5)

Retrieval

get()

Summary

That's all.

I hope it can be helpful for someone.

For feedback or complaints, please contact me via TwitterDM.

See you!

Popular Articles

Deploying PHP 7.4 + Laravel 6 Project to AWS EC2

Implementing Breadcrumbs in Laravel with laravel-breadcrumbs

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!