0

我正在使用 Lumen 8.x 版本。我需要在中间件中有当前找到的控制器和操作,以便我可以进行一些身份验证。但我发现这是不可能的,因为管道就像 Middleware1 -> Middleware2-> do the dispatching -> controller@action() -> Middleware2 -> Middleware1。

因此,在调度之前,我无法获得路线信息。在 $controller->action() 之后这样做肯定是不对的。

我做了一些研究,发现了这一点。

$allRoutes = $this->app->getRoutes();
$method = \Request::getMethod();
$pathInfo = \Request::getPathInfo();
$currentRoute = $allRoutes[$method.$pathInfo]['action']['uses'];

但这在访问类似 URI 时对我不起作用app/role/1,因为$allRoutes只有索引app/role/{id}而不是app/role/1.

请建议我们如何做到这一点?非常感谢。

4

0 回答 0