Package Data | |
---|---|
Maintainer Username: | nouni.elbachir |
Maintainer Contact: | dowilcox@umflint.edu (Donald Wilcox) |
Package Create Date: | 2016-11-19 |
Package Last Update: | 2016-11-22 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:13:38 |
Package Statistics | |
---|---|
Total Downloads: | 646 |
Monthly Downloads: | 4 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Laravel 5 package to create navigation menus, based on KnpLabs/KnpMenu.
Add to your composer.json file
"enimiste/knp-menu-laravel": "2.*"
In config/app.php add the service provider and alias.
Dowilcox\KnpMenu\MenuServiceProvider::class,
'Menu' => Dowilcox\KnpMenu\Facades\Menu::class,
To Access the menu service directly :
$menu_builder = app('knp_menu.menu');
php artisan vendor:publish --tag=knp_menu
To define your custom renderer :
$app["knp_menu.matcher"]
To add custom Voter you implement the interface "Dowilcox\KnpMenu\Voter\OrderedVoterInterface" and register it in the service container with the tag "knp_menu.voter"
Set the lower order for Voter that should be executed in first.
It is recommended order values between 0 and than 100.
Your Voters will be executed first before the built in ones.
echo \Menu::render(\Menu::get('menu_name'))
$menu
holding the menu defined by the name "menu_name". This object is an instance of Knp\Menu\MenuItem
$menu = Menu::create('main-menu', ['childrenAttributes' => ['class' => 'nav']]);
/*
* This is the list of possible options for a menu item :
*
* 'uri' => null,
* 'label' => null,
* 'attributes' => array(),
* 'linkAttributes' => array(),
* 'childrenAttributes' => array(),
* 'labelAttributes' => array(),
* 'extras' => array(),
* 'current' => null,
* 'display' => true,
* 'displayChildren' => true,
*/
$menu->addChild('Home', [
'uri' => url('/'),
'attributes' => [
'class'=>'your_css_class',
],
'extras' => [
'routes' => [
['route' => 'route_name_1'],
['route' => 'route_name_2'],
]
]
]);
$menu->addChild('Users', ['uri' => route('admin.users.index')]);
$menu->addChild('Roles', ['uri' => route('admin.roles.index')]);
$menu->addChild('Menu', ['uri' => url('menu')]);
echo Menu::render($menu);
//Or
echo Menu::render($menu, $custom_render_options);//$custom_render_options is an array
Will output:
<ul class="nav">
<li class="first">
<a href="http://localhost:8000">Home</a>
</li>
<li class='your_css_class'>
<a href="http://localhost:8000/admin/users">Users</a>
</li>
<li class='your_css_class'>
<a href="http://localhost:8000/admin/roles">Roles</a>
</li>
<li class="current active last your_css_class">
<a href="http://localhost:8000/menu">Menu</a>
</li>
</ul>