Appending current url with the new one

2019-09-19 11:42发布

问题:

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

回答1:

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()
}}


回答2:

//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();