2
votes

So I have a products page where you may browse all products or browse queried products if you choose to. However in both cases they must have pagination. Here is my route:

Route::get('/products/{gender}/{subcategory_name}', [
    'uses' => 'ProductsController@showProducts',
    'as' => 'products'
]);

For the pagination links I use $model->links() in my views. Both the pagination and query work. When you decide to query the items you must still paginate them. However when I click to go to the second page the pagination url deletes my query url. The result is loosing the queried products and getting to the second page but with ALL products, not the Queried ones. Here is an step by step walkthrough for clarification:

  1. I am on this url: products/Men/T-shirt
  2. I click on the second pagination link so I can get to this url: "products/Men/T-shirt?page=2" // This works
  3. I decide to query the items. Here is the url afterwards: "products/Men/T-shirt?color%5B%5D=1" // This works. I query the products and get the correct pagination links.
  4. Now here is the problem. When I click the second pagination link of the queried products the pagination url delets my query url and I go to this link "products/Men/T-shirt?page=2". Now I am on the second page of ALL not the queried products. I need to go to the second page of the QUERIED products.

Solutions and advice are welcome. Thanks in advance!

1
try to set sortkey=color&page={{Input::get('page','')}} in the anchor tagPardeep Pathania
Input is deprecated in Laravel 5.2. Even though I could most likely use Request instead of Input, I couldn't understand what you meant. Could explain with more details? @PardeepPathaniaCodearts

1 Answers

3
votes

You need to tell Laravel to append your own query parameters to the links() method, for example:

{{ $model->appends(['color' => Request::input('color')])->links() }}

To have the query params dynamically you could use something like:

{{ $model->appends(Request::except('page'))->links() }}