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"' : '' }}>
Try Below Code to write each li tag for check some text in URL
if (strpos($_SERVER['REQUEST_URI'], "ScamType") !== false){
echo "active";
}
Write above code in class.
Ex.
<li class="{{ if (strpos($_SERVER['REQUEST_URI'], "ScamType") !== false){ echo "active"; } }}"><a href="{{route('ScamType.index')}}"><i class="icon icon-home"></i> <span>Scam Type</span></a> </li>
From above answer I have try and doesnt work because class="active" must be class=active
<li><a class="{{ request()->routeIs('about.index*') ? 'active-menu' : '' }}" href="{{route('about.index')}}"><i class="fa fa-desktop"></i> About</a></li>