mwafi mwafi - 3 months ago 18
PHP Question

Laravel 5: get route parameters in associative array

Can I return all of route parameters in associative array, excluding normal GET/POST parameters?

sample:

route: user/{id}
requested url: user/1?test=bla
required array: Array ( [id] => 1 ) //exclude normal GET variable value "test"


I know I can use
request
methods:
route()
&
__get()
, but they need me to know the variable key before use them:

$request->route('id')
$request->__get('id') //Its value will be changed if normal get variable has same name passed


I need to return associated array with all passed parameters in route,
thx,

Answer

You can try this:

Route::current()->parameters();