'How to activate the sidebar menu?
I'm using template adminpanel chain-responsive-bootstrap3-admin-template When a parent menu is active it should have a class of active.
When a parent menu with sub menus is active and also in a dropdown active state the class should be parent active.
How to make the class change dynamically?
<ul class="nav nav-pills nav-stacked">
<li><a href="{{ route('dashboard') }}"><i class="fa fa-home"></i> <span>Home</span></a></li>
<li><a href="#"><i class="fa fa-suitcase"></i> <span>Orders</span></a></li>
<li class="parent"><a href="#"><i class="fa fa-shopping-cart"></i> <span>Shop</span></a>
<ul class="children">
<li><a href="{{ route('category.index') }}">Categories</a></li>
<li><a href="{{ route('product.index') }}">Products</a></li>
<li><a href="{{ route('product-attribute.index') }}">Attributes</a></li>
<li><a href="">filters</a></li>
<li><a href="">Uploads</a></li>
<li><a href="{{ route('page.index') }}">Pages</a></li>
</ul>
</li>
<li class="parent"><a href="#"><i class="fa fa-share"></i> <span>Marketing</span></a>
<ul class="children">
<li><a href="{{ route('stock.index') }}">Stocks</a></li>
<li><a href="{{ route('coupon.index') }}">Coupons</a></li>
</ul>
</li>
<li class="parent"><a href="#"><i class="fa fa-users"></i> <span>Users and Roles</span></a>
<ul class="children">
<li><a href="{{ route('user.index') }}">Users</a></li>
<li><a href="#">Roles</a></li>
</ul>
</li>
</ul>
Solution 1:[1]
Try out this.
Put this in your helper.
function activeMenu($uri = '')
{
$active = '';
if (Request::is(Request::segment(1) . '/' . $uri . '/*') || Request::is(Request::segment(1) . '/' . $uri) || Request::is($uri)) {
$active = 'active';
}
return $active;
}
Write this code in your sidebar blade file.
<li class="{{ activeMenu('dashboard') }}">
<a href="{{ route('dashboard') }}"><i class="fa fa-user-secret"></i> <span class="nav-label">Dashboard </span> </a>
</li>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | VIKAS KATARIYA |
