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

    <tfoot id='wTnoM'></tfoot><legend id='wTnoM'><style id='wTnoM'><dir id='wTnoM'><q id='wTnoM'></q></dir></style></legend>

        • <bdo id='wTnoM'></bdo><ul id='wTnoM'></ul>
      1. 选择前 10 行 - Laravel Eloquent

        时间:2023-09-23
      2. <i id='XLEvX'><tr id='XLEvX'><dt id='XLEvX'><q id='XLEvX'><span id='XLEvX'><b id='XLEvX'><form id='XLEvX'><ins id='XLEvX'></ins><ul id='XLEvX'></ul><sub id='XLEvX'></sub></form><legend id='XLEvX'></legend><bdo id='XLEvX'><pre id='XLEvX'><center id='XLEvX'></center></pre></bdo></b><th id='XLEvX'></th></span></q></dt></tr></i><div id='XLEvX'><tfoot id='XLEvX'></tfoot><dl id='XLEvX'><fieldset id='XLEvX'></fieldset></dl></div>
          <bdo id='XLEvX'></bdo><ul id='XLEvX'></ul>

              <tfoot id='XLEvX'></tfoot>
              <legend id='XLEvX'><style id='XLEvX'><dir id='XLEvX'><q id='XLEvX'></q></dir></style></legend>

            • <small id='XLEvX'></small><noframes id='XLEvX'>

                <tbody id='XLEvX'></tbody>

                  本文介绍了选择前 10 行 - Laravel Eloquent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  到目前为止,我有以下模型:

                  So far I have the following model:

                  class Listing extends Eloquent {
                       //Class Logic HERE
                  }
                  

                  我想要一个基本函数来检索表列表"的前 10 行并将它们传递给视图(通过控制器?).

                  I want a basic function that retrieves the first 10 rows of my table "listings" and passes them on to the view (via a controller?).

                  我知道这是一项非常基本的任务,但我找不到一个简单的指南来实际解释如何显示一组基本结果,同时详细说明模型、控制器和视图文件中的要求.

                  I know this a very basic task but I can't find a simple guide that actually explains step-by-step how to display a basic set of results, whilst detailing what is required in the model, controller and view files.

                  推荐答案

                  首先你可以使用分页器.这很简单:

                  First you can use a Paginator. This is as simple as:

                  $allUsers = User::paginate(15);
                  
                  $someUsers = User::where('votes', '>', 100)->paginate(15);
                  

                  变量将包含一个分页器类的实例.您的所有数据都将存储在 data 键下.

                  The variables will contain an instance of Paginator class. all of your data will be stored under data key.

                  或者您可以执行以下操作:

                  Or you can do something like:

                  旧版本的 Laravel.

                  Old versions Laravel.

                  Model::all()->take(10)->get();
                  

                  较新版本的 Laravel.

                  Newer version Laravel.

                  Model::all()->take(10);
                  

                  有关更多阅读,请考虑以下链接:

                  For more reading consider these links:

                  • 分页文档
                  • 将数据传递给视图
                  • Eloquent 基本用法
                  • 备忘单

                  这篇关于选择前 10 行 - Laravel Eloquent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel 中的 BelongsTo 和 HasOne 有什么区别 下一篇:Laravel 获取相关模型的类名

                  相关文章

                  最新文章

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

                    <bdo id='kL1VB'></bdo><ul id='kL1VB'></ul>

                    <legend id='kL1VB'><style id='kL1VB'><dir id='kL1VB'><q id='kL1VB'></q></dir></style></legend>

                      <tfoot id='kL1VB'></tfoot>
                    1. <small id='kL1VB'></small><noframes id='kL1VB'>