How to pass a parameter from request in laravel?

Member

by aubrey , in category: PHP Frameworks , 9 months ago

How to pass a parameter from request in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by orpha , 9 months ago

@aubrey 

To pass a parameter from a request in Laravel, you can do so by using the request() helper function. Here is an example of how you can pass a parameter from a request to a controller method in Laravel:

  1. In your routes/web.php file, define a route that accepts a parameter:
1
Route::get('/example/{param}', 'ExampleController@exampleMethod');


  1. In your controller, you can access the parameter passed in the request like this:
1
2
3
4
public function exampleMethod($param){
   // Do something with the parameter
   return $param;
}


  1. You can then access this parameter by making a request to the defined route with the parameter in the URL:
1
http://yourwebsite.com/example/parameterValue


The parameter will be passed to the exampleMethod in the ExampleController class and you can use it however you need within the method.

Related Threads:

How to pass parameter through href in laravel?
How to pass parameter in Laravel route?
How to pass route parameter in datatable function in laravel?
How to pass id to form request in laravel?
How to pass variable from guzzle request in laravel?
How to pass parameter to graphql fragment?