Setting active states for navigation

Submitted by mattems - 4 years ago

An easy helper method that will assist in setting active classes for navigation items based on the current route.

//throw this in your helper.php
function set_active($path, $active = 'active') {

    return call_user_func_array('Request::is', (array)$path) ? $active : '';


// use it like so
<a class="{{ set_active(['admin/institutes*','admin/courses*']) }}">Learning</a>

// you can pass a single string to a route or multiple and wildcards
comments powered by Disqus