How to get value of URL parameters into Controller (Laravel)

1. If you have your parameter attached to the URL after the question mark like

http://www.yoursite.com/controllerMethod?key=value

Your route for this controller will look something like this

Route::get('controllerMethod', $controller . 'controllerMethod');

You can get the value of this parameter in your controller function by

public function controllerMethod() {
   $key = Input::get('key');
   echo $key;
}

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

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

Your route for this controller will look something like this

Route::get('controllerMethod/{key}', $controller . 'controllerMethod');

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;
}

Web Stuff Enthusiast.

Related Posts

1 comments On How to get value of URL parameters into Controller (Laravel)

Leave a reply:

Your email address will not be published.

Site Footer