This is my routes.php
:
$app->get('/users/{id}/', ['middleware' => 'example', function () {
return "users";
}]);
This is the handle
function in the middleware:
public function handle($request, Closure $next)
{
// I would like to get the value of the url parameter {id} here
return $next($request);
}
Is there a way I can get the parameter id
from my middleware?
* Edit *
I'm using Lumen 5.1.0.
There are some conventional ways in Laravel doesn't work on Lumen. And get parameter form URI in middleware is one of them. In Laravel, I just need to call $request->id
, it will work like magic. But here in order to get parameter in Lumen, I need to do something like this:
$request->route()[2]['id']