如何在Laravel中获取以前的分页数据?

时间:2023-01-27 16:29:14

I try something like that

我尝试过类似的东西

User::paginate(10);

And when I click 2 via my view it's go /?page=2 and it's just show after record 10. How do I get previous pagination data?

当我通过我的视图点击2时,它是go /?page = 2并且它只是在记录10之后显示。如何获得以前的分页数据?

Why I want to get the previous data? Don't want to go with 1,2,3, pagination. Want to show 10 records, 20 records, 30 records and etc.

为什么我想获取以前的数据?不想与1,2,3,分页。想要显示10条记录,20条记录,30条记录等。

2 个解决方案

#1


When changing the page size in the dropdown menu (lets say the field name is pageSize)you want to send the request to the controller again, query the data and paginate with the selected value.

当您在下拉菜单中更改页面大小(假设字段名称为pageSize)时,您希望再次将请求发送到控制器,查询数据并使用所选值进行分页。

User::paginate(Input:get('pageSize', 10));

#2


In your view, change:

在您看来,更改:

$users->render();

to:

$users->appends(['foo' => 'bar'])->render();

Where you obviously replace foo and bar with the data you want to passed to the rest of the pages.

显然,您要将foo和bar替换为要传递给其余页面的数据。

Documentation

#1


When changing the page size in the dropdown menu (lets say the field name is pageSize)you want to send the request to the controller again, query the data and paginate with the selected value.

当您在下拉菜单中更改页面大小(假设字段名称为pageSize)时,您希望再次将请求发送到控制器,查询数据并使用所选值进行分页。

User::paginate(Input:get('pageSize', 10));

#2


In your view, change:

在您看来,更改:

$users->render();

to:

$users->appends(['foo' => 'bar'])->render();

Where you obviously replace foo and bar with the data you want to passed to the rest of the pages.

显然,您要将foo和bar替换为要传递给其余页面的数据。

Documentation