kylemassacre / laravel-menus
Laravel Menu management
Requires
- php: ^8.0
- illuminate/config: ^9.21|^10.0|^12.0
- illuminate/support: ^9.21|^10.0|^12.0
- illuminate/view: ^9.21|^10.0|^12.0
- spatie/laravel-html: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.40.0
- mockery/mockery: ^1.6.0
- orchestra/testbench: ^8.10.0|^9.0
- phpunit/phpunit: ^10.1
Suggests
- spatie/laravel-html: A modern alternative to laravelcollective/html which is no longer supported
This package is auto-updated.
Last update: 2025-04-26 22:57:51 UTC
README
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.