我的分页有点问题.

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).

我会尽快测试这段代码,但它应该可以工作.无论如何都要告诉我!

Laravel相关问答推荐

如何使中继器项目计数动态Laravel Filament V3?

Laravel FAKER语法

查询Laravel中的图形

将 ID 传递给资源控制器进行编辑

如何从laravel中的另一个表中获取用户名

如何在 laravel 5.3 中验证没有 auth:api 中间件的用户?

为什么命令php artisan serve不起作用

如何在 Laravel Passport 中获取刷新令牌?

合并和排序两个 Eloquent 集合?

无法安装 Laravel 包 - 干预图像

Laravel 5 文件下载:stream() 或 download()

laravel 5中的配置缓存导致找不到视图

在 Laravel Eloquent 中,limit 与 take 有什么区别?

Laravel Eloquent:计算总价的最佳方法

在 laravel 6.0 中未定义命令ui

如何仅在Blade模板存在时才包含它?

Laravel Eloquent 模型中的字段

Laravel 4:将什么作为参数传递给 Url 类?

如何在 laravel 用户删除中重置自动增量?

[Vue 警告]:找不到元素:#app