juy/active-menu
Laravel helper to add an “active” CSS class based on the current route name. Supports exact, wildcard, and multiple route patterns via facade, container, or helper, plus a Blade directive. Configurable active class value.
active class to menu items based on the current route name. This aligns well with common frontend navigation patterns in Laravel applications.<a href="{{ route('dashboard') }}">). Less ideal for SPAs or JavaScript-driven navigation.Active) and a service provider, requiring minimal changes to existing code. No database or external API dependencies.config/activemenu.php, reducing hardcoding in views.Route::current()->getName()).posts.{id}).activeIfRoute()) to avoid dependency risks?route() helpers.Route::macro('active', function ($routeName, $defaultClass = 'active') {
return request()->routeIs($routeName) ? $defaultClass : '';
});
config/activemenu.php to match the project’s CSS class naming conventions.active classes with the facade:
<li class="{{ Active::route('dashboard') }}">Dashboard</li>
Blade::directive('active', function ($routeName) {
return "<?php echo request()->routeIs($routeName) ? 'active' : ''; ?>";
});
<li class="@active('dashboard')">Dashboard</li>
boot() method signatures.Route::current() is deprecated; replace with request()->route().create_function).activemenu.php.active classes in Blade templates incrementally (start with low-traffic pages).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Laravel version incompatibility | Active classes not applied | Use polyfills or custom route logic |
| Route name changes | Incorrect active classes | Document route naming conventions |
| PHP version incompatibility | Package fails to load | Downgrade PHP or fork the package |
| Missing service provider registration | Facade unavailable | Verify config/app.php updates |
| Dynamic route names | False positives/negatives | Exclude dynamic routes from checks |
How can I help you explore Laravel packages today?