F
Filament11mo ago
Forever

Third Layer Navigation.

Im tryint to setup a third layer of navigation using the navigation builder on the panel i defnied:
->navigation(function (NavigationBuilder $builder): NavigationBuilder {

$builder->groups(
array_merge(
[NavigationGroup::make('Dashboard')->items([NavigationItem::make('Dashboard')->url('/boot/dashboard.asp')->icon('heroicon-o-home')])],
Modul::query()
->where('hidden', 0)
->orderBy('OrderId')
->get()
->map(fn (Modul $modul) => $modul->getNavigationGroup())
->toArray()
));

return $builder;
});
->navigation(function (NavigationBuilder $builder): NavigationBuilder {

$builder->groups(
array_merge(
[NavigationGroup::make('Dashboard')->items([NavigationItem::make('Dashboard')->url('/boot/dashboard.asp')->icon('heroicon-o-home')])],
Modul::query()
->where('hidden', 0)
->orderBy('OrderId')
->get()
->map(fn (Modul $modul) => $modul->getNavigationGroup())
->toArray()
));

return $builder;
});
Modul is just an Model with function:
use Filament\Navigation\NavigationGroup as FilamentNavigationGroup;

public function getNavigationGroup(): NavigationGroup
{
$navigationItems = $this->menuItems()->where('unlocked', '=', 1)->whereNull("parent")->get()->map(fn (NavigationItem $navigationItem) => $navigationItem->registerAsNavigationItem())->toArray();

return FilamentNavigationGroup::make($this->LabelDE)
->icon(preg_match('/class\s*=\s*["\']([^"\']+)["\']/', $this->icon, $matches) ? $matches[1] : '')
->items($navigationItems)
->collapsed(true);
}
use Filament\Navigation\NavigationGroup as FilamentNavigationGroup;

public function getNavigationGroup(): NavigationGroup
{
$navigationItems = $this->menuItems()->where('unlocked', '=', 1)->whereNull("parent")->get()->map(fn (NavigationItem $navigationItem) => $navigationItem->registerAsNavigationItem())->toArray();

return FilamentNavigationGroup::make($this->LabelDE)
->icon(preg_match('/class\s*=\s*["\']([^"\']+)["\']/', $this->icon, $matches) ? $matches[1] : '')
->items($navigationItems)
->collapsed(true);
}
Solution:
Solution:
$navItem->childItems([...$children])
$navItem->childItems([...$children])
`...
Jump to solution
14 Replies
Forever
ForeverOP11mo ago
Continue due to Message Limit NavigationItems is also a Model from my OLD App:
use Filament\Navigation\NavigationItem as FilamentNavigationItem;

public function registerAsNavigationItem(): \Filament\Navigation\NavigationItem
{
$navItem = \Filament\Navigation\NavigationItem::make(($this->parent ? '-- ' : '').$this->LabelDE)
->url(str_replace('#{ROOT}', '', $this->UrlBoot))
->icon($this->icon)
->sort($this->orderId)
->isActiveWhen(fn () => $_SERVER['REQUEST_URI'] == str_replace('#{ROOT}', '', $this->UrlBoot));

if ($this->parent) {
$navItem->group($this->parent->LabelDE)->parentItem($this->parent->LabelDE);
} else {
$navItem->group($this->LabelDE)->parentItem($this->Modul->LabelDE ?? 'Missing Module');
}

return $navItem;

}
use Filament\Navigation\NavigationItem as FilamentNavigationItem;

public function registerAsNavigationItem(): \Filament\Navigation\NavigationItem
{
$navItem = \Filament\Navigation\NavigationItem::make(($this->parent ? '-- ' : '').$this->LabelDE)
->url(str_replace('#{ROOT}', '', $this->UrlBoot))
->icon($this->icon)
->sort($this->orderId)
->isActiveWhen(fn () => $_SERVER['REQUEST_URI'] == str_replace('#{ROOT}', '', $this->UrlBoot));

if ($this->parent) {
$navItem->group($this->parent->LabelDE)->parentItem($this->parent->LabelDE);
} else {
$navItem->group($this->LabelDE)->parentItem($this->Modul->LabelDE ?? 'Missing Module');
}

return $navItem;

}
According to Dan That should already be possible
Forever
ForeverOP11mo ago
No description
Forever
ForeverOP11mo ago
but maybe im using the parent parameter wrong? Model Columns : ID | Modul | parent (which is just the ID of the parent in the same table) | hidden | icon | orderId | LabelDE | UrlBoot
Dan Harrin
Dan Harrin11mo ago
$item->items([item item item]) to add child items to a parent
Forever
ForeverOP11mo ago
Method Filament\Navigation\NavigationItem::items does not exist.
Forever
ForeverOP11mo ago
Flare
Method Filament\Navigation\NavigationItem::items does not exist. - The error occurred at https://next.local.i2k.ch/m/1/boot/dashboard.asp
Forever
ForeverOP11mo ago
its childItems
Dan Harrin
Dan Harrin11mo ago
try childItems() ye
Forever
ForeverOP11mo ago
Do i have to do something esle i only see the parent item and not the childitem
public function registerAsNavigationItem(string $base_path): \Filament\Navigation\NavigationItem
{
$navItem = \Filament\Navigation\NavigationItem::make($this->LabelDE)
->url($base_path . str_replace('#{ROOT}', '', $this->UrlBoot))
->sort($this->orderId)
->isActiveWhen(fn() => $_SERVER['REQUEST_URI'] == str_replace('#{ROOT}', '', $this->UrlBoot))
->icon("heroicon-o-arrow-top-right-on-square");

if ($this->children()->count() > 0) {
$navItem
->childItems($this->children()
->get()
->map(fn(NavigationItem $navigationItem) => $navigationItem
->registerAsNavigationItem($base_path))
->toArray()
);
}
return $navItem;

}
public function registerAsNavigationItem(string $base_path): \Filament\Navigation\NavigationItem
{
$navItem = \Filament\Navigation\NavigationItem::make($this->LabelDE)
->url($base_path . str_replace('#{ROOT}', '', $this->UrlBoot))
->sort($this->orderId)
->isActiveWhen(fn() => $_SERVER['REQUEST_URI'] == str_replace('#{ROOT}', '', $this->UrlBoot))
->icon("heroicon-o-arrow-top-right-on-square");

if ($this->children()->count() > 0) {
$navItem
->childItems($this->children()
->get()
->map(fn(NavigationItem $navigationItem) => $navigationItem
->registerAsNavigationItem($base_path))
->toArray()
);
}
return $navItem;

}
`
Dan Harrin
Dan Harrin11mo ago
once the parent item is active, you'll be able to see the children
Forever
ForeverOP11mo ago
that means it only renders childitems when its active ?
Dan Harrin
Dan Harrin11mo ago
yes same as how github handles third level nav
Forever
ForeverOP11mo ago
not ideal for my usecase (damn legacy compatibility) is there a way to just set it active wenn i open the "modul" ? like when i give it a url like #modul_parentID
Solution
Forever
Forever10mo ago
Solution:
$navItem->childItems([...$children])
$navItem->childItems([...$children])
`
Want results from more Discord servers?
Add your server