PHPackages                             elmdash/menu - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. elmdash/menu

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

elmdash/menu
============

A simple laravel menu structure

1.0.7(7y ago)03.0k1MITPHPPHP &gt;=5.5.9CI failing

Since Jul 11Pushed 5y agoCompare

[ Source](https://github.com/elmdash/menu)[ Packagist](https://packagist.org/packages/elmdash/menu)[ RSS](/packages/elmdash-menu/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (9)Used By (0)

ElmDash Menu
------------

[](#elmdash-menu)

Menus are but a simple tree structure. You can implement them a million ways, but this is a clean and minimal menu structure that handles the basic chores of setting active states and toggling menu items depending on a user's authorization within Laravel apps.

In your provider's boot method add something like:

```
$m = new \ElmDash\Menu\Menu('top');

// a login route, only visible to guests
$m->add('access')->guests();

// menu items for users with proper permissions
$m->add('books.edit', function (Menu $books) {
	$books->can('edit-books');

	// It's optional to edit within callbacks.
	// However, this will be called once the menu is rendered
	// (instead of immediately)
});

// an adit route, active for any account routes
$m->add('account.edit')->match('account.*');

// you can also nest items
$c = $m->add('event.create');

// you may add route parameters that are
// included when determining active states
$c->add('event.create')->params(['type' => 'basic']);
$c->add('event.create')->params(['type' => 'special']);

// more menu items
$m->add('logout');

$this->app->instance('menu-top', $m);
```

Then in your view:

```
{% set menu = app.make('menu-top') %}

            {% for item in menu.children %}
               {% set activeClass = item.isActive ? 'active' : '' %}

                        {{ item.label }}

                    {% for subitem in item.children %}
                        {% set activeClass = subitem.isActive ? 'active': '' %}

                                {{ subitem.label }}

                    {% endfor %}

            {% endfor %}

```

Labels are set in `lang/menu.php`:

```
