Ad

Laravel 4 Pagination Links Ignore Existing GET Parameters

- 1 answer

I have a search in Laravel 4. After search for sh my url is this:

http://localhost/musiter/product/search-products/24?query=sh

I also have pagination there, but the pagination for the second link for example is:

http://localhost/musiter/product/search-products/24?page=2

instead of:

http://localhost/musiter/product/search-products/24?query=sh&page=2

Any way to fix this?

Ad

Answer

The code you're looking for is:

$paginator->appends(['query' => $value])->links();

You can add to the query string of pagination links using the appends method on the Paginator:

<?php echo $users->appends(array('sort' => 'votes'))->links(); ?>

This will generate URLs that look something like this:

http://example.c>
http://example.com/something?page=2&sort=votes

If you wish to append a "hash fragment" to the paginator's URLs, you may use the fragment method:

<?php echo $users->fragment('foo')->links(); ?>

This method call will generate URLs that look something like this:

http://example.com/something?page=2#foo

You can also check [Laravel documentation].1

Ad
source: stackoverflow.com
Ad