用于URL包含参数的Laravel活动菜单项 [英] Laravel active menu item for url included parameters
本文介绍了用于URL包含参数的Laravel活动菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在列表项中设置活动类,但是它不起作用.
I'm trying to set active class in my list item, but it doesn't work.
我在刀片中的代码:
@foreach($data as $site)
<ul class="sidebar-menu" id="second-menu">
@if(isAdmin())<li class="{{-- active class for url parameter --}}"><a href="{{ url('sites/'.$site->id.'/edit') }}" >{{ $site->name }}</a></li>
@endif
</ul>
@endforeach
所以,如果我写:li class ="@ if(getRouteName()=='site @ index'){{'active'}} @ endif",效果很好,但是在我的情况下,问题是我想在foreach sites/'.$ site-> id.'/edit
So, if I write: li class="@if(getRouteName() == 'site@index'){{ 'active' }}@endif" , it works nice, but in my case the problem is that I want to get 'active' class in foreach sites/'.$site->id.'/edit
非常感谢.
推荐答案
使用 is()
方法.例如:
Use is()
method. For example:
<li class="{{ request()->is('sites/*/edit') ? 'active' : '' }}"
这篇关于用于URL包含参数的Laravel活动菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文