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)
6363 return collect ();
6464 }
6565
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
6670 return $ menu ->menuItems ()
67- ->with (' linkable ' , ' children ' )
71+ ->with ($ eagerLoadRelations )
6872 ->visible ()
6973 ->ordered ()
70- ->get ()
71- ->toTree ();
74+ ->get ();
7275 }
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+
7394}
You can’t perform that action at this time.
0 commit comments