Laravel: How to get last N entries from DB

前端 未结 7 848
太阳男子
太阳男子 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

提交回复
热议问题