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

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

        <tfoot id='B8t6s'></tfoot>

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

        限制 Laravel 分页显示的链接数量

        时间:2023-09-24

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

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

                1. <small id='gAbJr'></small><noframes id='gAbJr'>

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

                  <tfoot id='gAbJr'></tfoot>
                  本文介绍了限制 Laravel 分页显示的链接数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有什么简单的方法可以限制 Laravel 分页显示的链接数量?

                  Any easy way to limit how many links are shown with Laravels pagination?

                  目前最多显示 13 个链接(上一页,1 2 3 4 5 7 8 .. 78 79 下一页)

                  Currently it shows 13 links at most (Prev, 1 2 3 4 5 7 8 .. 78 79 next)

                  然而,这对于移动设备来说太多了,变成了两行导航......有没有办法将链接设置为例如只显示 10 个?

                  This however is too much for mobile devices and becomes a two line navigation... is there any way to set the links to e.g. only show 10?

                  我搞乱了分页演示者,但实际上似乎没有任何效果.

                  I have messed around with the pagination presenter but nothing actually seemed to work.

                  谢谢

                  推荐答案

                  定义自定义演示者的旧方法不适用于 Laravel 5.3+,显示的链接数量似乎是在 中硬编码的Illuminate/Pagination/UrlWindow::make() 的 $onEachSide 参数:

                  The old way of defining a custom presenter doesn't work with Laravel 5.3+, the number of links shown seems to be hard-coded in the $onEachSide parameter of Illuminate/Pagination/UrlWindow::make():

                  public static function make(PaginatorContract $paginator, $onEachSide = 3)
                  

                  我最终只是编写了自己的 render() 函数,从 LengthAwarePaginator

                  I ended up just writing my own render() function, stealing some code from LengthAwarePaginator

                  /**
                       * Stole come code from LengthAwarePaginator::render() and ::elements() to allow for a smaller UrlWindow
                       *
                       * @param LengthAwarePaginator $paginator
                       * @param int $onEachSide
                       * @return string
                       */
                      public static function render(LengthAwarePaginator $paginator, $onEachSide = 2)
                      {
                          $window = UrlWindow::make($paginator, $onEachSide);
                  
                          $elements = array_filter([
                              $window['first'],
                              is_array($window['slider']) ? '...' : null,
                              $window['slider'],
                              is_array($window['last']) ? '...' : null,
                              $window['last'],
                          ]);
                  
                          return LengthAwarePaginator::viewFactory()->make(LengthAwarePaginator::$defaultView, [
                              'paginator' => $paginator,
                              'elements' => $elements,
                          ])->render();
                      }
                  }
                  

                  我们使用 Twig,所以我将其注册为 Twig 过滤器,我想可以为 Blade 做类似的事情.

                  We use Twig, so I registered this as a Twig filter, I imagine something similar could be done for Blade.

                  这篇关于限制 Laravel 分页显示的链接数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在自定义 WP_Query Ajax 上实现分页 下一篇:使用 Youtube Data API V3 和 Google API Client PHP 将视频上传到 Youtub

                  相关文章

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

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

                    • <bdo id='xtt2f'></bdo><ul id='xtt2f'></ul>

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