F
Filamentβ€’12mo ago
SJ

Dynamic Navigation with SubMenus not displaying

I build a dynamic Navigation from an Array with this function:
public function createNavigation(): Array
{
$navigation = [];
foreach (config('b65.navigation') as $menu => $submenus) {

foreach ($submenus as $submenu => $items) {

$navigation[] = NavigationItem::make($submenu)
->icon('heroicon-o-home')
->group($menu);

foreach ($items as $title => $link) {

$navigation[] = NavigationItem::make($title)
->url($link, shouldOpenInNewTab: true)
->parentItem($submenu)
->group($menu);

}

}

}

return $navigation;

}
public function createNavigation(): Array
{
$navigation = [];
foreach (config('b65.navigation') as $menu => $submenus) {

foreach ($submenus as $submenu => $items) {

$navigation[] = NavigationItem::make($submenu)
->icon('heroicon-o-home')
->group($menu);

foreach ($items as $title => $link) {

$navigation[] = NavigationItem::make($title)
->url($link, shouldOpenInNewTab: true)
->parentItem($submenu)
->group($menu);

}

}

}

return $navigation;

}
` But the Navigation does not show the Items in the SubMenus. What am I missing? The Documentation states, that the Navigation Item in the Submenu must contain the same Group from its parent.
No description
6 Replies
SJ
SJOPβ€’11mo ago
This drives me nuts, please any help will be appreciated Still nothing? Will I have to open an official Bug Report?
Lara Zeus
Lara Zeusβ€’11mo ago
I think you should use NavigationGroup::make() for the parent items then create all items without nesting, set the group and it should work
SJ
SJOPβ€’11mo ago
I did that. Unforunately I do get the same result. You cannot return any NavigationGroup Object within the navigationItems() Array and separating the creation of the groups to the navigationGroups Array results in an Error "Call to a member function keyBy() on null" because filament()->getNavigation(); seens not to see the group .. as i stated i wasted hours on this with any possible combinations 😦
Lara Zeus
Lara Zeusβ€’11mo ago
create the NavigationGroup separately from NavigationItem
->navigationGroups(getGroupsOnlyAsArray())
->navigationItems(createNavigation())
->navigationGroups(getGroupsOnlyAsArray())
->navigationItems(createNavigation())
SJ
SJOPβ€’11mo ago
.. separating the creation of the groups to the navigationGroups Array results in an Error "Call to a member function keyBy() on null" because filament()->getNavigation(); seems not to see the group .. tried it 😦 Sorry but i think this seems to be a bug. I will try a bug report on github Thanks for the replies!
Want results from more Discord servers?
Add your server