• <i id='oVCgu'><tr id='oVCgu'><dt id='oVCgu'><q id='oVCgu'><span id='oVCgu'><b id='oVCgu'><form id='oVCgu'><ins id='oVCgu'></ins><ul id='oVCgu'></ul><sub id='oVCgu'></sub></form><legend id='oVCgu'></legend><bdo id='oVCgu'><pre id='oVCgu'><center id='oVCgu'></center></pre></bdo></b><th id='oVCgu'></th></span></q></dt></tr></i><div id='oVCgu'><tfoot id='oVCgu'></tfoot><dl id='oVCgu'><fieldset id='oVCgu'></fieldset></dl></div>

      <small id='oVCgu'></small><noframes id='oVCgu'>

      1. <legend id='oVCgu'><style id='oVCgu'><dir id='oVCgu'><q id='oVCgu'></q></dir></style></legend>
          <bdo id='oVCgu'></bdo><ul id='oVCgu'></ul>
      2. <tfoot id='oVCgu'></tfoot>

        Laravel:如何从数据库中获取最后 N 个条目

        时间:2023-09-24
          • <bdo id='G8FlY'></bdo><ul id='G8FlY'></ul>

              <small id='G8FlY'></small><noframes id='G8FlY'>

              <i id='G8FlY'><tr id='G8FlY'><dt id='G8FlY'><q id='G8FlY'><span id='G8FlY'><b id='G8FlY'><form id='G8FlY'><ins id='G8FlY'></ins><ul id='G8FlY'></ul><sub id='G8FlY'></sub></form><legend id='G8FlY'></legend><bdo id='G8FlY'><pre id='G8FlY'><center id='G8FlY'></center></pre></bdo></b><th id='G8FlY'></th></span></q></dt></tr></i><div id='G8FlY'><tfoot id='G8FlY'></tfoot><dl id='G8FlY'><fieldset id='G8FlY'></fieldset></dl></div>

                <tbody id='G8FlY'></tbody>
                <tfoot id='G8FlY'></tfoot>
                <legend id='G8FlY'><style id='G8FlY'><dir id='G8FlY'><q id='G8FlY'></q></dir></style></legend>

                1. 本文介绍了Laravel:如何从数据库中获取最后 N 个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的数据库中有狗表,我想检索 N 个最新添加的狗.

                  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:

                  Dogs:all()->where(time, <=, another_time);
                  

                  还有其他方法吗?例如像这样的 Dogs:latest(5);

                  Is there another way how to do it? For example something like this Dogs:latest(5);

                  非常感谢您的帮助:)

                  推荐答案

                  你可以试试这样的:

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

                  使用 orderByDescending 顺序并取前 n 条记录.

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

                  更新(因为添加了latest方法):

                  Update (Since the latest method has been added):

                  $dogs = Dogs::latest()->take(5)->get();
                  

                  这篇关于Laravel:如何从数据库中获取最后 N 个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Eloquent 只获取一列作为数组 下一篇:Laravel Eloquent LEFT JOIN WHERE NULL

                  相关文章

                  最新文章

                  <i id='2OCXS'><tr id='2OCXS'><dt id='2OCXS'><q id='2OCXS'><span id='2OCXS'><b id='2OCXS'><form id='2OCXS'><ins id='2OCXS'></ins><ul id='2OCXS'></ul><sub id='2OCXS'></sub></form><legend id='2OCXS'></legend><bdo id='2OCXS'><pre id='2OCXS'><center id='2OCXS'></center></pre></bdo></b><th id='2OCXS'></th></span></q></dt></tr></i><div id='2OCXS'><tfoot id='2OCXS'></tfoot><dl id='2OCXS'><fieldset id='2OCXS'></fieldset></dl></div>

                    <bdo id='2OCXS'></bdo><ul id='2OCXS'></ul>

                    <legend id='2OCXS'><style id='2OCXS'><dir id='2OCXS'><q id='2OCXS'></q></dir></style></legend>
                    1. <tfoot id='2OCXS'></tfoot>

                    2. <small id='2OCXS'></small><noframes id='2OCXS'>