我的分页有点问题.
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.
我的分页有点问题.
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.
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):
/**
* Set the input page parameter name used by the paginator.
*
* @param string $pageName
* @return void
*/
public function setPageName($pageName)
{
$this->pageName = $pageName;
}
现在考虑到你将有另外一个查询字符串附加到URL,所以你需要告诉分页来考虑它.使用appends()
法:
$collection1->appends(array_except(Request::query(), 'page'))->links();
$collection2->appends(array_except(Request::query(), 'other_page'))->links();
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).
我会尽快测试这段代码,但它应该可以工作.无论如何都要告诉我!