Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lumen: how can I get url parameters from middleware

Tags:

php

laravel

lumen

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.

like image 287
Andrea Avatar asked Jul 07 '15 15:07

Andrea


1 Answers

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']
like image 189
Phi Nguyen Avatar answered Sep 23 '22 15:09

Phi Nguyen