I have a controller method in Laravel 5.1 that takes both GET and POST requests.
There are some variables I have to pass in to that method.
So I'd pass the variable in like this:
http://localhost/<methodName>/<var1 value>/<var2 value>
I'd like Laravel's Request object to be populated with those variables.
Of course I can do:
http://localhost/<MethodName>?var1=var1_value&var2=var2_value
But I'd like to keep the pretty url mentioned before and still be able to populate Request object.
public function methodName(Request $request)
{
dd($request);
}
This return an empty array.
Yes, I can do something like:
public function methodName(Request $request, $var1= "", $var2 = "")
{
dd($var1." ".$var2);
}
This will return the variables but I'd really like to have the Request object populated if possible.
The route I'm using is:
Route::match(['get', 'post'],
'/<method-name>/{<var1_value>?}/{<var2_value>?}/{<var3_value>?}',
'<ControllerName>@<methodName>');
Post variables are not a problem.