Skip to content

laravel 5 controller get url parameters

Last updated on December 13, 2015

The Request facade will grant you access to the current request that is bound in the container.Remember, if you are in a namespace, you will have to import the Request facade using a use Request; statement at the top of your class file.

You can access parameters several ways, let me show you some of the methods,

Method 1 :

If you have your parameter attached to the URL without question mark like

http://www.yoursite.com/controllerMethod/indexAction/value

Your route for this controller will look something like this
get('controllerMethod/indexAction/{key}','controllerMethod@indexAction');

You can get the value of this parameter in your controller function by passing the same name of variable in your controller method as you used in the route.

public function controllerMethod($key) {
   echo $key;
}

Method 2 :

You can access all the request data with Request facade, below is the snippet.

public function controllerMethod(Request $request) {
   $input  = $request->all();
   dd($input);
}
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments