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>