File tree Expand file tree Collapse file tree 5 files changed +130
-0
lines changed
Expand file tree Collapse file tree 5 files changed +130
-0
lines changed Original file line number Diff line number Diff line change 1+ /vendor /
2+ .DS_Store
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " sukristyan/laravel-menu-wrapper" ,
3+ "description" : " A lightweight Laravel package to simplify building dynamic and structured menus in your applications." ,
4+ "type" : " library" ,
5+ "keywords" : [
6+ " laravel" ,
7+ " menu" ,
8+ " dynamic menu" ,
9+ " laravel-menu" ,
10+ " group menu"
11+ ],
12+ "license" : " MIT" ,
13+ "autoload" : {
14+ "psr-4" : {
15+ "Sukristyan\\ LaravelMenuWrapper\\ " : " src/"
16+ }
17+ },
18+ "authors" : [
19+ {
20+ "name" : " sukristyan" ,
21+ "email" : " hi@galih.me"
22+ }
23+ ],
24+ "require" : {
25+ "php" : " ^8.1"
26+ },
27+ "minimum-stability" : " dev" ,
28+ "prefer-stable" : true ,
29+ "config" : {
30+ "sort-packages" : true
31+ },
32+ "extra" : {
33+ "laravel" : {
34+ "providers" : [
35+ " Sukristyan\\ LaravelMenuWrapper\\ CustomRouteProvider"
36+ ]
37+ }
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Sukristyan \LaravelMenuWrapper ;
4+
5+ use Illuminate \Routing \Route ;
6+ use Illuminate \Support \ServiceProvider ;
7+ use Sukristyan \LaravelMenuWrapper \Facade \RegisterMenu ;
8+
9+ final class CustomRouteProvider extends ServiceProvider
10+ {
11+ /**
12+ * Register any application services.
13+ */
14+ public function register (): void
15+ {
16+ $ this ->app ->singleton ('navigation-menu ' , function () {
17+ return new RegisterMenu ();
18+ });
19+ }
20+
21+ /**
22+ * Bootstrap any application services.
23+ */
24+ public function boot (): void
25+ {
26+ Route::macro ('groupMenu ' , function (string $ label ) {
27+ RegisterMenu::groupping ($ label );
28+ return $ this ;
29+ });
30+
31+ Route::macro ('menu ' , function (string $ label ) {
32+ RegisterMenu::add ($ this ->uri (), $ label );
33+ return $ this ;
34+ });
35+
36+ Route::macro ('group ' , function ($ attributes , $ routes ) {
37+ $ result = \Illuminate \Support \Facades \Route::buildGroup ($ attributes , $ routes );
38+ RegisterMenu::endGroupping ();
39+ return $ result ;
40+ });
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Sukristyan \LaravelMenuWrapper \Facade ;
4+
5+ use Illuminate \Support \Facades \Facade ;
6+
7+ class RegisterMenu extends Facade
8+ {
9+ protected static $ menus = [];
10+ protected static $ currentGroup = null ;
11+
12+ public static function groupping ($ label )
13+ {
14+ self ::$ currentGroup = $ label ;
15+ self ::$ menus [$ label ] = [];
16+ }
17+
18+ public static function endGroupping ()
19+ {
20+ self ::$ currentGroup = null ;
21+ }
22+
23+ public static function add ($ uri , $ label )
24+ {
25+ if (self ::$ currentGroup ) {
26+ self ::$ menus [self ::$ currentGroup ][$ uri ] = $ label ;
27+ }
28+ }
29+
30+ public static function all ()
31+ {
32+ return self ::$ menus ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ return [
4+ /**
5+ * ----------------------------------------------------------------------
6+ * Determine the grouping method that will be used to group your menus
7+ * this will only apply if you are using groupMenu.
8+ * ----------------------------------------------------------------------
9+ * Refer to the README.md
10+ * Possible value: key, item
11+ */
12+ 'group_by ' => 'key '
13+ ];
You can’t perform that action at this time.
0 commit comments