silveragency

This is how I add active classes. I first create a functions file app/Helpers/functions.php and add this function:

    /* Set active class
    -------------------------------------------------------- */
    function set_active($path, $active = 'active') {
        return call_user_func_array('Request::is', (array)$path) ? $active : '';
    }

I then add this to autoload in composer.json

    "autoload": {
        "classmap": {...},
        "psr-4": {...},
        "files": [
            "app/Helpers/functions.php"
        ]
    },

Then run composer dumpautoload.

And then use the function like so:


    <ul>
        <li class="dropdown {{ set_active(['page', 'page/*']) }}">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Page</a>
            <ul class="dropdown-menu" role="menu">
                <li class="{{ set_active(['page/child-1']) }}">
                    <a href="{{ url('page/child-1') }}">Child 1</a>
                </li>
                <li class="{{ set_active(['page/child-2']) }}">
                    <a href="{{ url('page/child-2') }}">Child 2</a>
                </li>
                <li class="{{ set_active(['page/child-3']) }}">
                    <a href="{{ url('page/child-3') }}">Child 3</a>
                </li>
            </ul>
        </li>
    </ul>

This will add the active class to .dropdown for the routes: /page and any child routes /page/*

e.g /page/child-1, /page/child-2, /page/child-3

and will also add the active class to each relevant child page.

Return to Thread...