Skip to content

Commit 07f5d45

Browse files
authored
Merge pull request #2 from sukristyan/dev
release v1.0.1
2 parents 5031eca + e2db3bb commit 07f5d45

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Laravel Menu Wrapper
2+
3+
Laravel Menu Wrapper is a lightweight package that helps you manage dynamic menus in your Laravel app with less effort.
4+
5+
> Simply put, this package automatically generates an array of menus based on what you define.
6+
7+
Tested on Laravel `10.x`, `11.x`, and `12.x` — works successfully without any issues.
8+
9+
# Installation
10+
11+
Using Composer (recommended):
12+
13+
```sh
14+
cd your-laravel-project
15+
composer require sukristyan/laravel-menu-wrapper
16+
```
17+
18+
After the installation is complete, the provider and configuration files will be published automatically.
19+
20+
# Configuration
21+
22+
Currently, there are only 2 configuration items.
23+
24+
## Group As (`group_as`)
25+
26+
Values: `item` or `key`.
27+
28+
This setting determines how your menus will be grouped.
29+
30+
`key` means that your group label will be used as the array key. Your defined menu will look like this:
31+
32+
```php
33+
[
34+
'Group Name' => [
35+
[
36+
'label' => 'Menu #1',
37+
],
38+
[
39+
'label' => 'Menu #2',
40+
]
41+
],
42+
...
43+
]
44+
```
45+
46+
`item` means that your group label will be included in the array as `group_name`, and your defined menus will be inserted under `childs`. Your menu will look like this:
47+
48+
```php
49+
[
50+
[
51+
'group_name' => 'Group Name',
52+
'childs' => [
53+
[
54+
'label' => 'Menu #1',
55+
],
56+
[
57+
'label' => 'Menu #2',
58+
],
59+
],
60+
],
61+
...
62+
]
63+
```
64+
65+
## Populated Items (`populated_items`)
66+
67+
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.
68+
69+
```php
70+
'populate_items' => function (Route $route) {
71+
return [
72+
'route_name' => $route->getName(),
73+
'type' => 'children'
74+
];
75+
}
76+
```
77+
78+
# Usage
79+
80+
> NOTE: All collected data will follow what you define in `config/laravel-menu-wrapper.php`.
81+
82+
Go to your 'routes/web.php', and add the `menu('Menu Label', 'Group Label')` function to your route:
83+
84+
```php
85+
Route::get('index', [DashboardController::class, 'index'])
86+
->name('index')
87+
->menu('Dashboard');
88+
```
89+
90+
After that, you can run `php artisan menu:list` to show all your menus. You can also get all menus using this code:
91+
92+
```php
93+
app('sukristyan.menu')->all();
94+
```
95+
96+
You can parse the resulting menu array and use it anywhere in your project.
97+
98+
You can directly use it in a `foreach` loop, or create a custom page to manage the menu — allowing administrators to add or remove menu items for users.
99+
100+
```php
101+
$menus = app('sukristyan.menu')->all();
102+
103+
foreach ($menus as $menu) {
104+
...
105+
}
106+
```
107+
108+
# License
109+
110+
The `sukristyan/laravel-menu-wrapper` package is open-sourced software licensed under the [MIT license](https://github.com/sukristyan/laravel-menu-wrapper/blob/master/LICENSE).

config/laravel-menu-wrapper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
* ----------------------------------------------------------------------
1212
* Possible value: key, item
1313
*/
14-
'group_as' => 'key',
14+
'group_as' => 'item',
1515

1616
'populate_items' => function (Route $route) {
1717
return [
1818
'route_name' => $route->getName(),
19-
'uri' => $route->uri(),
20-
'method' => $route->getActionMethod(),
2119
];
2220
}
2321
];

0 commit comments

Comments
 (0)