Admin Menu

Through Config File Deprecated

You can add items to the menu by editing config/enso/menu.php. Don't.

Through the Facade

You should edit the menu using the EnsoMenu facade.

You will want to do this in a service provider appropriate to your code. If you're making a website (rather than an Enso package/product), you probably want to do it in the EnsoServiceProvider that php artisan enso:install creates.

You can add Menu items as either data arrays, or as pre-created Items. If you are providing an Item, it must implement Yadda\Enso\Menu\Contracts\ItemInterface.

use EnsoMenu;
use Yadda\Enso\Menu\Item;

...

EnsoMenu::addItems([
    [
        'route' => ['admin.things.index'],
        'label' => 'Things',
        'icon' => 'fa fa-bicycle',
        'order' => 5,
        'restrict' => 'permission', // OR
        'restrict' => ['permission', 'permission'], // OR
        'restrict' => function ($menu_item) { return true || false; }
    ]
]);

EnsoMenu::addItems([
    new Item([
        'route' => ['admin.things.index'],
        'label' => 'Things',
        'icon' => 'fa fa-bicycle',
        'order' => 5,
    ]),
]);

Route

This should be an array that is spread into the Laravel route() helper. It will end up as route(...$item->getRoute()) if it is set.

Url

If no route option is set, you can instead use a hard coded Url. Routes are preferred, if possible.

Label

This is the label for the menu item

Icon

This is the class that will be applied to the <i> element. Currently, we use font-awesome icons.

Order

The order parameter is an arbitrary number. Home will always be first, Log out will always be last and everything else will fall between. Default items include:

  • Pages (order = 50)
  • Users (order = 98)
  • Roles (order = 99)

Restrict

The restrict parameter is used to remove the Menu item from the menu under pre-defined circumstances. You can provide any one of:

  • A permission name. Users who do not have this permission cannot view this item.
  • An array of permission names. Users who do not have any of these permission cannot view this item.
  • A callable. This will expect to receive the menu_item as a parameter, and will return true if the item should show, and false it not.

Useful function calls

EnsoMenu::addItem(array)
EnsoMenu::addItems(array)
EnsoMenu::updateItemByLabel(string $label, array $updates)
EnsoMenu::removeItemByLabel(string $label)