Laravel: How to get last N entries from DB

前端 未结 7 845
太阳男子
太阳男子 2021-02-01 01:07

I have table of dogs in my DB and I want to retrieve N latest added dogs.

Only way that I found is something like this:

Do         


        
相关标签:
7条回答
  • 2021-02-01 01:35

    You may also try like this:

    $recentPost = Article::orderBy('id', 'desc')->limit(5)->get();
    

    It's working fine for me in Laravel 5.6

    0 讨论(0)
提交回复
热议问题