1

I'm implementing manual pagination using the LenghtAwarePagination class and it works but when I use:

{{ $result->links() }}

in the search view, it generates the links without taking the current URL into account. Like this:

<ul>
  <li><a href="/">1</a></li>
  <li><a href="/?page=2">2</a></li>
  <li><a href="/?page=3">3</a></li>
  <li><a href="/?page=4">4</a></li>
</ul>

So, the URL is like this:

mypage.com/search/63.231237/12.4491092/?filter=true&filter2=true

I think it would be too much trouble to append each parameter one by one to the pagination links so how can I take whatever is after mypage.com, in this case this:

/search/63.231237/12.4491092/?filter=true&filter2=true

. So I need to replace this:

/
/?page=2 
/?page=3
/?page=4

for this:

/search/63.231237/12.4491092/?filter=true&filter2=true
/search/63.231237/12.4491092/?filter=true&filter2=true&page=2
/search/63.231237/12.4491092/?filter=true&filter2=true&page=3
/search/63.231237/12.4491092/?filter=true&filter2=true&page=4

How can I do it from within the links function?

EDIT: I got it to work using this:

$currentURL = $_SERVER["REQUEST_URI"];
$result= $this->paginate($results)->withPath($currentURL);

But there's a problem, I need to strip page=x out of $currentURL, how can I do that?

nick
  • 2,819
  • 5
  • 33
  • 69
  • Try this: https://stackoverflow.com/a/41976594 – Jannes Botis Sep 30 '17 at 21:13
  • For the first problem you can use laravel helpers to get the current url in the view like this `url()->current()` for the second one you can use php's strtok function like this `$currentURL = strtok($currentURL, '&').strtok('&');` :) – Maraboc Oct 02 '17 at 09:53

0 Answers0