Appending current url with the new one

2019-09-19 11:20发布

I have a request with this URL

expenses?startDate=2019-05-09&endDate=2019-05-15

now what I wanted is to append the startDate=2019-05-09&endDate=2019-05-15 to the new request URL so that I can go to the second page with the current result

expenses?pages=2&startDate=2019-05-09&endDate=2019-05-15

I tried

$builder->latest()->paginate(10)->appends(request()->query());

but when i click to my pagination it is not appending thus I get only

expenses?pages=2

any idea how can I achieve this?

PS. im not using blade

2条回答
手持菜刀,她持情操
2楼-- · 2019-09-19 11:44
//in your query
$query = Model::paginate(25); // your query with all conditions
$query->appends(request()->query());

return $query;

// in blade add if need
$query->appends(request()->input())->links();
查看更多
贪生不怕死
3楼-- · 2019-09-19 11:48

I think you are little bit confused. request()->query() will be available only in page 1 but after it will be null.

So you are getting only the page in get method.

In your blade try this:

{{
$paginatorVar->appends(request()->input())->links()
}}
查看更多
登录 后发表回答