Laravel: How to get last N entries from DB

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

    You may try something like this:

    $dogs = Dogs::orderBy('id', 'desc')->take(5)->get();
    

    Use orderBy with Descending order and take the first n numbers of records.

提交回复
热议问题