kalnoy / illuminate-menu
A menu builder for Laravel using Bootstrap's markup.
Installs: 13 963
Dependents: 1
Suggesters: 0
Security: 0
Stars: 24
Watchers: 5
Forks: 3
Open Issues: 0
pkg:composer/kalnoy/illuminate-menu
Requires
- php: >=5.4.0
Requires (Dev)
- illuminate/http: 4.2 - 5.6
- illuminate/support: 4.2 - 5.6
- mockery/mockery: ~0.9
README
A menu builder for Laravel 4-5 using Bootstrap's markup.
Note that this package is shipped with no styles nor scripts, you have to download them manually from Twitter Bootstrap's site.
Installation
Install using Composer:
composer require kalnoy/illuminate-menu:~1.0
Add a service provider:
'providers' => [ 'Illuminate\Html\MenuServiceProvider', ],
And a facade:
'aliases' => [ 'Menu' => 'Illuminate\Support\Facades\Menu', ],
Documentation
Rendering a menu:
{!! Menu::render($items, $attributes) !!}
Where $attributes is optional array of html attributes for ul element.
Rendering a list of menu items:
<ul>{!! Menu::items($items) !!}</ul>
Rendering a single menu item:
{!! Menu::item($label, $url) !!}
{!! Menu::item($label, $options) !!}
{!! Menu::item($options) !!}
See a list of available options below.
Basic example:
Menu::render([ 'Link to url' => 'bar', 'Link to external url' => 'http://bar', [ 'label' => 'Link to url', 'url' => 'bar' ], 'Link to route' => [ 'route' => [ 'route.name', 'foo' => 'bar' ] ], ]);
Rendering an item with a drop down menu:
{!! Menu::item([
'label' => 'Settings',
'icon' => 'wrench',
'items' => [
'Foo' => 'bar',
'-', // divider
'Logout' => [ 'route' => 'logout_path' ],
],
]) !!}
Controlling whether the item is visible:
{!! Menu::item([
'label' => 'Foo',
'url' => 'bar',
'visible' => function () { return Config::get('app.debug'); },
] !!}
Item options
You can specify an array of following options:
labelis a label of the item, automatically translated, so you can specify lang string idurlis the url which can be a full URI or local pathrouteto specify a route, possibly with parameterssecure; specifytrueto makeurlbe secure (doesn't affectrouteoption)itemsis an array of items for drop down menulinkOptionsis an array of additional link attributes
Changing the state of the item:
visibleis a boolean value or closure to specify whether the item is visibleactiveis a boolean value or closure to specify whether to addactiveclass to item; if not specified, determined automatically based on current urldisabledis a boolean value or closure to specify whether the menu item is disabled
Presentation options:
iconis a glyphicon id, i.e.pencilbadgeis a value for badge (scalar or closure)- and any other parameter that will be rendered as an attribute for
<li>element.
Customization
Though this menu builder intended to be used together with bootstrap markup, you can customize it however you like by
extending Illuminate\Html\MenuBuilder class and overriding base methods.