在Laravel v4中,我可以使用…
Route::currentRouteName()
我如何在Laravel v5和Laravel v6中做到这一点?
在Laravel v4中,我可以使用…
Route::currentRouteName()
我如何在Laravel v5和Laravel v6中做到这一点?
当前回答
如果你想在多条路线上选择菜单,你可以这样做:
<li class="{{ (Request::is('products/*') || Request::is('products') || Request::is('product/*') ? 'active' : '') }}"><a href="{{url('products')}}"><i class="fa fa-code-fork"></i> Products</a></li>
或者如果你想只选择一个菜单,你可以简单地这样做:
<li class="{{ (Request::is('/users') ? 'active' : '') }}"><a href="{{url('/')}}"><i class="fa fa-envelope"></i> Users</a></li>
在Laravel 5.2中也进行了测试
希望这能帮助到一些人。
其他回答
您可以使用以下方法:
Route::getCurrentRoute()->getPath();
在Laravel版本> 6.0中,您可以使用以下方法:
$route = Route::current();
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
没有人有答案,如果路由名称或url id需要在视图直接 对于视图direct上的路由名
$routeName = Request::route()->getName();
对于id from url on view
$url_id = Request::segment(2);
如果你需要url,而不是路由名,你不需要使用/需要任何其他类:
url()->current();
要求::路径();更好,记住使用Request;
现在在Laravel 5.3中,我看到可以做出类似的尝试:
$route = Route::current();
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
https://laravel.com/docs/5.3/routing#accessing-the-current-route