-1

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

Beginner
  • 1,700
  • 4
  • 22
  • 42
  • `$builder->latest()->paginate(10)->appends(Illuminate\Support\Facades\Input::except('page'))` is this working? OR `$builder->latest()->paginate(10)->appends(request()->except('page'))->links()` – Rahul May 16 '19 at 09:26
  • still not and it is still the same – Beginner May 16 '19 at 09:29
  • Check this [link](https://github.com/laravel/framework/issues/19441) for more help. – Rahul May 16 '19 at 09:31
  • Possible duplicate of [How to automatically append query string to laravel pagination links?](https://stackoverflow.com/a/52664376/2260604) check solution by Rasmus Christoffer Nielsen – Nicklas Kevin Frank May 16 '19 at 10:23
  • i just dont understand why it doesnt append the new url. Btw my pagination is built on front end and it just fetches data on the base on the page links. im not using blade templating engine – Beginner May 16 '19 at 10:31

2 Answers2

0

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()
}}
halfer
  • 19,824
  • 17
  • 99
  • 186
ManojKiran A
  • 5,896
  • 4
  • 30
  • 43
-1
//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();
Abdullah Al Shakib
  • 2,034
  • 2
  • 15
  • 16