Laravel: How to get last N entries from DB

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

    My solution for cleanliness is:

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

    It's the same as other answers, just with using built-in methods to handle common practices.

提交回复
热议问题