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

        <bdo id='bW1yZ'></bdo><ul id='bW1yZ'></ul>
      <legend id='bW1yZ'><style id='bW1yZ'><dir id='bW1yZ'><q id='bW1yZ'></q></dir></style></legend>

        一页中的 Laravel 多分页

        Laravel Multiple Pagination in one page(一页中的 Laravel 多分页)

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

              <tbody id='BFyCs'></tbody>

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

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

                  问题描述

                  我的分页出了点问题.我有两个包含来自数据库的数据的表,我使用 laravel 分页器对它进行了分页.

                  I'm having some trouble with my pagination. I'm having two tables with data from a database and I paginated it with laravel Paginator.

                  现在我的问题是,例如,当您转到第 2 页时,它会添加 ?page=2 但这会使第一个表格也转到第 2 页.

                  Now my problem is when you go to, for example, page 2 it adds ?page=2 but that makes the first table go to page 2 too.

                  反正有这样的东西吗?

                  page_table1={number}&page_table2={number}

                  因此您不会将页面更改应用于其他表格.

                  so you don't apply the page change on other tables.

                  推荐答案

                  很遗憾我现在无法测试此代码,只能浏览文档和代码(在 Illuminate/Pagination/Environment) 我猜你可能是这样的:

                  Unfortunately I can't test this code right now, but browsing at the docs and the code (in Illuminate/Pagination/Environment) I guess you could something like this:

                  # use default 'page' for this
                  $collection1 = Model::paginate(20);
                  
                  # use custom 'other_page' for this
                  $collection2 = Model2::paginate(20);
                  $collection2->setPageName('other_page');
                  

                  setPageName() 方法未在文档中记录,但它是与文档中指出的方法一起的公共方法,因此它应该可以正常工作.供参考,这是声明(vendor/laravel/framework/src/Illuminate/Pagination/Environment.php 中的 l. 171-180):

                  The setPageName() method isn't documented in the docs, but it's a public method alongside those indicated in the documentation, so it should be working fine. FOr reference, this is the declaration (l. 171-180 in vendor/laravel/framework/src/Illuminate/Pagination/Environment.php):

                  /**
                   * Set the input page parameter name used by the paginator.
                   *
                   * @param  string  $pageName
                   * @return void
                   */
                  public function setPageName($pageName)
                  {
                      $this->pageName = $pageName;
                  }
                  

                  现在考虑到您将有另一个查询字符串附加到 url,因此您需要告诉分页考虑它.使用 appends() 方法:

                  Now take into consideration that you will have another query string appended to the url, so you need to tell the pagination to consider it. Use the appends() method:

                  $collection1->appends(array_except(Request::query(), 'page'))->links();
                  
                  $collection2->appends(array_except(Request::query(), 'other_page'))->links();
                  

                  也就是说,告诉每个 Presenter 用所有查询字符串(由 Request::query() 产生的数组没有使用的当前索引来构建 url分页器,否则你最终会得到一个双倍值).array_except() 是一个 Laravel 内置的数组助手,它返回给定数组(第一个参数)清除了传递的索引(第二个参数).

                  That is, tell each Presenter to build up the url with all the query strings (the array resulting from Request::query() without the current index used by the paginator, or you'll end up with a double value). array_except() is a Laravel built in array helper that returns the given array (1st parameter) purged of the passed index (2nd parameter).

                  我会尽快尝试测试此代码,但它应该可以工作.无论如何请告诉我!

                  I'll try to test this code as soon as I can, but it should work. Let me know in any case!

                  这篇关于一页中的 Laravel 多分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)
                  <legend id='jXkC8'><style id='jXkC8'><dir id='jXkC8'><q id='jXkC8'></q></dir></style></legend>
                    <tbody id='jXkC8'></tbody>

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

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

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