在Laravel v4中,我可以使用…

Route::currentRouteName()

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


当前回答

使用幼虫助手和魔法方法

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

其他回答

找到了一种查找当前路由名称的方法,适用于laravel v5, v5.1.28和v5.2.10

名称空间

use Illuminate\Support\Facades\Route;

and

$currentPath= Route::getFacadeRoot()->current()->uri();

对于Laravel Laravel v5.3,你可以使用:

use Illuminate\Support\Facades\Route;

Route::currentRouteName();

你可以使用下面的代码在刀片文件中获取路由名称

request()->route()->uri

使用Laravel 5.1,您可以使用

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

您可以使用以下方法:

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

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

$route = Route::current();

$name = Route::currentRouteName();

$action = Route::currentRouteAction();

如果你需要url,而不是路由名,你不需要使用/需要任何其他类:

url()->current();