My HTML code is
<div id="sidebar"><a href="#" class="visible-phone"><i class="icon icon-home"></i>Dashboard</a>
<ul>
<li class="active"><a href="{{route('ScamType.index')}}"><i class="icon icon-home"></i> <span>Scam Type</span></a> </li>
<li> <a href="{{route('ScamDatabase.index')}}"><i class="icon icon-signal"></i> <span>Scam Database</span></a> </li>
<li> <a href="{{route('ScamStory.index')}}"><i class="icon icon-inbox"></i> <span>Scam Story</span></a> </li>
<li><a href="{{route('KeyWord.index')}}"><i class="icon icon-th"></i> <span>Keyword</span></a></li>
<li><a href="{{route('Category.index')}}"><i class="icon icon-th"></i> <span>Category</span></a></li>
<li><a href="{{route('SubCategory.index')}}"><i class="icon icon-th"></i> <span>Sub Category</span></a></li>
</ul>
</div>
Here i gave li class active as like in bootstrap and its not working, but i don't know how to give in laravel and i am very beginner of laravel, so please avoid minus votes and give me the right solution for it.. How Should i change my code to get li class active dynamically?
You can use ternary operator. For example, you can check URI for the current route:
<li{{ request()->is('scam-types') ? ' class="active"' : '' }}>
You can also use *
as wildcard:
<li{{ request()->is('scam-type-number-*') ? ' class="active"' : '' }}>
Or you can check route name:
<li{{ request()->route()->getName() === 'ScamType.index' ? ' class="active"' : '' }}>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With