laravel-menus maintained by kylemassacre
Laravel Menus
Usage Example
To create menus in your Laravel application, you should create a file at app/Support/menus.php. This file will be automatically loaded by the package's service provider.
Basic Menu Creation
<?php
use KyleMassacre\Menus\Facades\Menu;
use KyleMassacre\Menus\MenuBuilder;
// Create a menu
Menu::create('main-menu', function (MenuBuilder $menu) {
// Add items to the menu
$menu->add([
'route' => 'home',
'title' => 'Home',
'icon' => 'fa fa-home fa-fw me-2',
]);
// Add a menu item with a URL instead of a route
$menu->add([
'url' => '/about',
'title' => 'About',
'icon' => 'fa fa-info fa-fw me-2',
]);
// Add a dropdown menu
$menu->dropdown('User', function ($sub) {
$sub->add([
'route' => 'profile',
'title' => 'Profile',
'icon' => 'fa fa-user fa-fw me-2',
]);
$sub->add([
'route' => 'logout',
'title' => 'Logout',
'icon' => 'fa fa-sign-out fa-fw me-2',
]);
});
});
Rendering Menus
To render a menu in your blade templates:
{!! Menu::render('main-menu') !!}
Or with a specific presenter:
{!! Menu::render('main-menu', 'App\\Http\\Presenters\\MainMenuPresenter') !!}
Important Notes
- Ensure your routes are defined before creating menus that reference them
- For route-based menu items, use
'route' => 'route.name'or'route' => ['route.name', ['param' => 'value']]for routes with parameters - For URL-based menu items, use
'url' => '/path/to/page'
Laravel Menus
kylemassacre/laravel-menus is a laravel package which created to manage menus. It has a feature called presenters which enables easy styling and custom structure of menu rendering.
This package is a re-published, re-organised and maintained version of nwidart/laravel-menus, which isn't maintained anymore. This package is used in AsgardCMS.
With one big added bonus that the original package didn't have: tests.
Documentation
You'll find installation instructions and full documentation on https://nwidart.com/laravel-menus/.
Credits
License
The MIT License (MIT). Please see License File for more information.