- Notifications
You must be signed in to change notification settings - Fork1
A lightweight Laravel package to simplify building dynamic and structured menus in your applications.
License
sukristyan/laravel-menu-wrapper
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Laravel Menu Wrapper is a lightweight package that helps you manage dynamic menus in your Laravel app with less effort.
Simply put, this package automatically generates an array of menus based on what you define.
Tested on Laravel10.x,11.x, and12.x — works successfully without any issues.
Using Composer (recommended):
cd your-laravel-projectcomposer require sukristyan/laravel-menu-wrapperAfter the installation is complete, the provider and configuration files will be published automatically.
Currently, there are only 2 configuration items.
Values:item orkey.
This setting determines how your menus will be grouped.
key means that your group label will be used as the array key. Your defined menu will look like this:
['Group Name' => [ ['label' =>'Menu #1', ], ['label' =>'Menu #2', ] ], ...]
item means that your group label will be included in the array asgroup_name, and your defined menus will be inserted underchilds. Your menu will look like this:
[ ['group_name' =>'Group Name','childs' => [ ['label' =>'Menu #1', ], ['label' =>'Menu #2', ], ], ], ...]
Here, you can define what you want to collect from the 'Illuminate\Routing\Route', or add custom identifiers to help integrate the menu into your application.
'populate_items' =>function (Route$route) {return ['route_name' =>$route->getName(),'type' =>'children' ];}
NOTE: All collected data will follow what you define in
config/laravel-menu-wrapper.php.
Go to your 'routes/web.php', and add themenu('Menu Label', 'Group Label') function to your route:
Route::get('index', [DashboardController::class,'index']) ->name('index') ->menu('Dashboard');
After that, you can runphp artisan menu:list to show all your menus. You can also get all menus using this code:
app('sukristyan.menu')->all();
You can parse the resulting menu array and use it anywhere in your project.
You can directly use it in aforeach loop, or create a custom page to manage the menu — allowing administrators to add or remove menu items for users.
$menus =app('sukristyan.menu')->all();foreach ($menusas$menu) {...}
Thesukristyan/laravel-menu-wrapper package is open-sourced software licensed under theMIT license.
About
A lightweight Laravel package to simplify building dynamic and structured menus in your applications.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.