Skip to content

Instantly share code, notes, and snippets.

@doulmi
Created January 4, 2017 09:50
Show Gist options
  • Save doulmi/14f20b166aa36fdf69fdd912b5975468 to your computer and use it in GitHub Desktop.
Save doulmi/14f20b166aa36fdf69fdd912b5975468 to your computer and use it in GitHub Desktop.
Laravel Navbar active
//Helper
/**
* Determine if this <li> is active
* return 'active' or ''
*/
public static function activeLi($routes)
{
if (is_string($routes)) {
return Route::currentRouteNamed($routes) ? 'active' : '';
} elseif (is_array($routes)) {
$active = false;
foreach ($routes as $route) {
if (Route::currentRouteNamed($route)) {
$active = true;
break;
}
}
return $active ? 'active' : '';
} else {
return '';
}
}
<li class="text-uppercase {{\App\Helper::activeLi(['demandes', 'index', 'demandes.show', 'demandes.edit'])}}"><a
href="{{route('demandes')}}">@lang('labels.demands')</a></li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment