Blade directives for Laravel 5.1+ to manage menu states in a clean and easy way., (*1)
Install
# 1) Require it with composer
composer require activismebe/laravel-active-menu
# 2) Register the Service provider in your config.
ActivismeBE\ActiveMenu\ActiveMenuServiceProvider::class,
Usage
Call @actvate(...)
to specify the activated menu:, (*2)
@activate('security_settings')
Now call @active(...)
irective to know if a specified menu is active:, (*3)
This directive will print the string active
if the given menu is activated. The example above will result on the following HTML:, (*4)
<ul>
<li>
<a href="/settings">Settings</a>
<ul class="dropdown">
<li class="active">
<a href="/settings/security">Security</a>
</li>
</ul>
</li>
</ul>
Now just add a li.active a { ... }
styles to your CSS and you're ready., (*5)
Using dot-notation
Use dot-notation to activate the menu cascade up, for example, using this directive:, (*6)
@activate('settings.security')
This will activate settings
and settings.security
, so the following directives will print the string active
:, (*7)
@active('settings')
@active('settings.security')
Change the class name
You can change the class name passing it as a second parameter:, (*8)
@active('user.account', 'link-active')
But I really recomend you stick to the convention and use the default value., (*9)