0

Let's say I'm paginating a list of items, and want to filter them by the first letter, my URL would be something like myURL.com/items?sortBy=C&page=2, this would return me the page 2 of the items that start with C. (Pagination is already working)

My question is, how do I retrieve the sortBy=C? And how the routes.php, and the controller would look like?

1 Answer 1

3

You can simply use the Input::get(), it takes the query string into consideration.

So, in your controller:

$letter = Input::get('sortBy');

You don't have to worry about your routes or your controller (I mean, you don't have to pass extra variables or check segments).

Example:

Route::get('items', array('as' => 'items', 'uses' => 'ItemsControllers@items'));

function items()
{
  $sort = Input::get('sortBy');

  // OR, if you want, you can check first for the index:
  if (Input::has('sortBy')) {
   $sort = Input::get('sortBy');
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, wow, didn't know Input::get() worked like that, thought it'd only work with the inputs inside forms, Thanks!

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.