For one, I'd recommend using a class for activation instead of an inline style. I use a couple macros for this, something like:
// Determines if menu items are active
HTML::macro('activeClass', function($pattern){
$matched = false;
// Force it to be an array
if(is_string($pattern))
{
$pattern = (array) $pattern;
}
foreach($pattern as $route)
{
// if it's a child route or the actual route
if(Request::is($route . '/*') OR Request::is($route))
{
$matched = true;
}
}
return $matched === true ? 'active' : '';
});
This is the important one
// Generates a list item with an anchor tag inside and automatically applies the active class
HTML::macro('nav', function($route, $title, $icon = null){
if($icon !== null)
{
$icon = Icon::$icon();
}
$link = '<li class="'.HTML::activeClass($route).'">';
$link .= '<a href="'.url($route).'">'.$icon.' '.$title.'</a>';
$link .= '<li>';
return $link;
});
I have the logic split into the two so I can re-use that activeClass macro to do activation in other cases such as submenus. I generally keep my macros in a separate file, app/macros.php and load it within the composer.json. Hope that helps!