Get current route name?

删除回忆录丶 提交于 2019-12-11 03:29:16

问题


In laravel I can use the following to get the current name of the route in my blade template:

{{ Route::currentRouteName() }}

How can I do the same in Lumen?


回答1:


example:

<?php
  $method = Request::getMethod();
  $pathInfo = Request::getPathInfo();
  $currentRoute = $app->getRoutes()[$method.$pathInfo];

  echo $currentRoute['action']['as'];
?>



回答2:


I fixed this with:

list($found, $routeInfo, $params) = app('request')->route() ?: [false, [], []];

$routeName = isset($routeInfo['as']) ? $routeInfo['as'] : null;



回答3:


This is how I do it

$request->route()[1]['uses'];


来源:https://stackoverflow.com/questions/31089939/get-current-route-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!