0

In Laravel, building a route takes the form:

Route::get('testing', function(){
    return 0 //whatever
});

If I want to include a query string, so that I could navigate to localhost/testing?p1=blah&p2=blah2..., is there a built in way to do this? The only thing I can think of is to use a single variable and parse the string myself:

Route::get('testing\\?{query}, function($query){ //I'm not sure if you have to escape the questionmark
    //parse the string manually
    return 0 //whatever
});

I feel like there must be a built in way to do this a little better, but I can't figure out what it is.

2 Answers 2

3

Query strings are not part of the route. You can get to them with request($key):

Route::get('testing', function(){
    return request('p1');
});

You can also get an associative array with everything in the query string, by calling the all method:

Route::get('testing', function(){
    return request()->all();
});

Note: if you're using an older version of Laravel, use Input::get() & Input::all(), respectively.

Sign up to request clarification or add additional context in comments.

Comments

0

You can also do request()->all() or request()->get('p1')

Comments

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.