public function my_method($route_param)
{
echo $route_param;
}
Mar 21, 2024
7
Level 8
What is the correct way to get route parameters values inside the controller?
Hello,
So far I've used a mix of 2 ways I found working.
Assuming I have the following in web.php:
Route::get('/some_url/{route_param}', [MyController::class, 'my_method']);
1:
public function my_method(Request $request)
{
$route_parameter = $request->route_param;
}
2:
public function my_method(Request $request)
{
$route_parameter = $request->route('route_param')
}
Is one preferred over the other? Or there is another way other than these 2 that is better?
Thanks
Please or to participate in this conversation.