在Laravel v4中,我可以使用…

Route::currentRouteName()

我如何在Laravel v5和Laravel v6中做到这一点?


当前回答

$request->route()->getName();

其他回答

在5.2中,你可以直接使用请求:

$request->route()->getName();

或者通过helper方法:

request()->route()->getName();

输出的例子:

"home.index"

您可以使用以下方法:

Route::getCurrentRoute()->getPath();

在Laravel版本> 6.0中,您可以使用以下方法:

$route = Route::current();

$name = Route::currentRouteName();

$action = Route::currentRouteAction();
\Request::path()

我用这个来获取当前uri

在控制器中访问当前路由名

Ie - http://localhost/your_project_name/edit

$request->segment(1);  // edit

(或)

$request->url();  // http://localhost/your_project_name/edit

使用Laravel 5.1,您可以使用

\Request::route()->getName()