File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,32 @@ protected function getMenuItems($menu, ?string $locale = null)
63
63
return collect ();
64
64
}
65
65
66
+ $ maxDepth = $ menu ->getEffectiveMaxDepth ();
67
+ $ eagerLoadRelations = $ this ->buildEagerLoadRelations ($ maxDepth );
68
+
69
+ // Get only top-level menu items with their visible children based on max depth
66
70
return $ menu ->menuItems ()
67
- ->with (' linkable ' , ' children ' )
71
+ ->with ($ eagerLoadRelations )
68
72
->visible ()
69
73
->ordered ()
70
- ->get ()
71
- ->toTree ();
74
+ ->get ();
72
75
}
76
+
77
+ protected function buildEagerLoadRelations (int $ maxDepth ): array
78
+ {
79
+ $ relations = ['linkable ' ];
80
+ $ currentPath = '' ;
81
+ $ depth = 1 ;
82
+
83
+ while ($ depth < $ maxDepth ) {
84
+ $ currentPath .= $ depth === 1 ? 'children ' : '.children ' ;
85
+ $ relations [$ currentPath ] = function ($ query ) {
86
+ $ query ->visible ()->ordered ()->with ('linkable ' );
87
+ };
88
+ $ depth ++;
89
+ }
90
+
91
+ return $ relations ;
92
+ }
93
+
73
94
}
You can’t perform that action at this time.
0 commit comments