The helper class for Laravel applications to get active class base on current route name
juy/active-menu is a Laravel package for the helper class for laravel applications to get active class base on current route name.
It currently has 5 GitHub stars and 3.125 downloads on Packagist (latest version 1.1.3).
Install it with composer require juy/active-menu.
Discover more Laravel packages by juy
or browse all Laravel packages to compare alternatives.
Last updated
Helper class for Laravel applications to get active class base on current route name (It's only detect "route name, this is enough for us.").
➜ composer require juy/active-menu
Manual install (alternative)
Simply add the following to the "require" section of your composer.json file, and run
composer updatecommand.
"juy/active-menu": "^1.1"
➜ composer remove juy/active-menu
Append this line to your service providers array in config/app.php.
Juy\ActiveMenu\ServiceProvider::class,
Publish config file.
➜ php artisan vendor:publish --provider="Juy\ActiveMenu\ServiceProvider" --tag="config"
You can modify css active class with custom one (default is 'active') in config/activemenu.php (after publish).
return [
// The default css class value if the request match given route name
'class' => 'active',
];
Alias/Facade
Active::route('route.name');
Application container
app('active')->route('route.name');
Helper function
active_route('route.name');
Wildcard samples
Active::route('route.name.*');
active_route('route.name.*');
Multi route with wilcard
Active::route(['route.name1.*', 'route.name2.*']);
active_route(['route.name1.*', 'route.name2.*']);
Custom blade directive
@ifActiveRoute('route.name')
<p>Foo</p>
@else
<p>Bar</p>
@endif
Real life usage
<li class="item {{ active_route('admin.index') }}">
<a href="admin/index">Dashboard</a>
</li>
This project is open-sourced software licensed under the MIT License.