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?

2
  • Try this: stackoverflow.com/a/41976594 Commented Sep 30, 2017 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('&'); :) Commented Oct 2, 2017 at 9:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.