在Laravel v4中,我可以使用…

Route::currentRouteName()

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


当前回答

你可以使用这行代码:url()->current()

在刀片文件中:{{url()->current()}}

其他回答

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

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

现在在Laravel 5.3中,我看到可以做出类似的尝试:

$route = Route::current();

$name = Route::currentRouteName();

$action = Route::currentRouteAction();

https://laravel.com/docs/5.3/routing#accessing-the-current-route

访问当前路由

在Blade模板中获取当前路由名

{{ Route::currentRouteName() }}

更多信息https://laravel.com/docs/5.5/routing#accessing-the-current-route

没有人有答案,如果路由名称或url id需要在视图直接 对于视图direct上的路由名

$routeName = Request::route()->getName();

对于id from url on view

$url_id = Request::segment(2);