在Laravel v4中,我可以使用…
Route::currentRouteName()
我如何在Laravel v5和Laravel v6中做到这一点?
在Laravel v4中,我可以使用…
Route::currentRouteName()
我如何在Laravel v5和Laravel v6中做到这一点?
当前回答
\Request::path()
我用这个来获取当前uri
其他回答
在我看来,最简单的解决方案是使用这个助手:
request()->route()->getName()
有关文档,请参见这个链接
有很多方法可以做到这一点。你可以输入:
\Illuminate\Support\Facades\Request::route()->getName()
获取路由名称。
Laravel 5.2可以使用
$request->route()->getName()
它会给你当前的路由名。
你可以使用下面的代码在刀片文件中获取路由名称
request()->route()->uri
访问当前路由
在Blade模板中获取当前路由名
{{ Route::currentRouteName() }}
更多信息https://laravel.com/docs/5.5/routing#accessing-the-current-route