php - Laravel 5.1 get variable from pretty URL to Request object -


i have controller method in laravel 5.1 takes both , post requests.

there variables have pass in method.

so i'd pass variable in this:

http://localhost/<methodname>/<var1 value>/<var2 value> 

i'd laravel's request object populated variables.

of course can do:

http://localhost/<methodname>?var1=var1_value&var2=var2_value 

but i'd keep pretty url mentioned before , still able populate request object.

public function methodname(request $request) {     dd($request); } 

this return empty array.

yes, can like:

public function methodname(request $request, $var1= "", $var2 = "") {     dd($var1." ".$var2); } 

this return variables i'd have 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 not problem.

in controller, use route() function on $request object.

$request->route('var1'); 

of course name of parameter must match define in routes.php

route::get('your/route/{var1}/{var2}','yourcontroller@method'); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -