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

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

Your route for this controller will look something like this

Route::get('/someRoute', [UserController::class, 'controllerMethod']);

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

public function controllerMethod(Request $request) {
   $key = $request->key
   echo $key;
}

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

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

Your route for this controller will look something like this

Route::get('someRoute/{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(Request $request, $key) {
   echo $key;
}

Next up, learn How to pass data from your controller / route to view files in Laravel

Comments