Access query string values from Laravel

For future visitors, I use the approach below for > 5.0. It utilizes Laravel’s Request class and can help keep the business logic out of your routes and controller.

Example URL


Route::get('get-grid-value', 'YourController@getGridValue');


 * $request is an array of data
public function getGridValue(Request $request)
    // returns "Foo"
    $object = $request->query('object');

    // returns "Bar"
    $value = $request->query('value');

    // returns array of entire input query...can now use $query['value'], etc. to access data
    $query = $request->all();

    // Or to keep business logic out of controller, I use like:
    $n = new MyClass($request->all());

For more on retrieving inputs from the request object, read the docs.

Leave a Comment