F
Filament11mo ago
Ron

Global navigation combined from multiple panels.

Is it possible to combine the navigation from multiple "sub" panels into a single app panel. I have an App panel with this code:
->navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder->items(
items: PanelNavigation::items()
);
})
->navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder->items(
items: PanelNavigation::items()
);
})
And PanelNavigation:items() calls module facades to pull the navigation items from respective panels
public static function items(): array
{
return [
NavigationItem::make('Dashboard')
->icon('mdi-view-dashboard')
->url(fn (): string => Dashboard::getUrl()),
...\Central::getNavigationItems(),
...\Logging::getNavigationItems(),
];

}
public static function items(): array
{
return [
NavigationItem::make('Dashboard')
->icon('mdi-view-dashboard')
->url(fn (): string => Dashboard::getUrl()),
...\Central::getNavigationItems(),
...\Logging::getNavigationItems(),
];

}
The getNavigationItems from a facade / module gets the resource navitems with the following
public function getNavigationItems(): array
{

return [
...CompanyResource::getNavigationItems(),
...CompanyThemeResource::getNavigationItems(),
...PropertyResource::getNavigationItems(),
];
}
public function getNavigationItems(): array
{

return [
...CompanyResource::getNavigationItems(),
...CompanyThemeResource::getNavigationItems(),
...PropertyResource::getNavigationItems(),
];
}
I use the same navigation builder in each panel and the code works only when running the /admin panel. When accessing the /app panel, the error is Route [filament.app.resources.companies.index] not defined. It appears that CompanyResource::getNavigationItems() is using the App panel to build the route Has anyone successfull built a global side nav with access to multiple panel resources?
Solution:
If anyone else comes across this, you can override the getUrl function in your resource and pass the panel ID, the url is then built correctly CompanyResource.php ``` public static function getUrl(string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string...
Jump to solution
1 Reply
Solution
Ron
Ron11mo ago
If anyone else comes across this, you can override the getUrl function in your resource and pass the panel ID, the url is then built correctly CompanyResource.php
public static function getUrl(string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
{
$panel = 'admin';

return parent::getUrl($name, $parameters, $isAbsolute, $panel, $tenant);
}
public static function getUrl(string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
{
$panel = 'admin';

return parent::getUrl($name, $parameters, $isAbsolute, $panel, $tenant);
}
Want results from more Discord servers?
Add your server