File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Admin/src/Resources/views/settings Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 20
20
21
21
<div class =" page-content settings-container" >
22
22
@php
23
- $settings = menu ()-> getItems ( ' admin ' ) -> first ( fn ( $item ) => $item -> getKey () == ' settings' )-> getChildren ();
23
+ $settings = menu ()-> getAdminMenuByKey ( ' settings' )-> getChildren ();
24
24
@endphp
25
25
26
26
@foreach ($settings as $setting )
Original file line number Diff line number Diff line change @@ -44,12 +44,18 @@ public function addItem(MenuItem $menuItem): void
44
44
/**
45
45
* Get all menu items.
46
46
*/
47
- public function getItems (?string $ area = null ): Collection
47
+ public function getItems (?string $ area = null , string $ key = '' ): Collection
48
48
{
49
49
if (! $ area ) {
50
50
throw new \Exception ('Area must be provided to get menu items. ' );
51
51
}
52
52
53
+ static $ items ;
54
+
55
+ if ($ items ) {
56
+ return $ items ;
57
+ }
58
+
53
59
$ configMenu = collect (config ("menu. $ area " ))->map (function ($ item ) {
54
60
return Arr::except ([
55
61
...$ item ,
@@ -74,7 +80,23 @@ public function getItems(?string $area = null): Collection
74
80
$ this ->prepareMenuItems ();
75
81
}
76
82
77
- return collect ($ this ->items )->sortBy (fn ($ item ) => $ item ->getPosition ());
83
+ $ items = collect ($ this ->items )->sortBy (fn ($ item ) => $ item ->getPosition ());
84
+
85
+ return $ items ;
86
+ }
87
+
88
+ /**
89
+ * Get admin menu by key or keys.
90
+ */
91
+ public function getAdminMenuByKey (array |string $ keys ): mixed
92
+ {
93
+ $ items = $ this ->getItems ('admin ' );
94
+
95
+ $ keysArray = (array ) $ keys ;
96
+
97
+ $ filteredItems = $ items ->filter (fn ($ item ) => in_array ($ item ->getKey (), $ keysArray ));
98
+
99
+ return is_array ($ keys ) ? $ filteredItems : $ filteredItems ->first ();
78
100
}
79
101
80
102
/**
You can’t perform that action at this time.
0 commit comments