Last active
September 4, 2025 07:09
-
-
Save neverything/d2045408954d8beb7c888256ba40a004 to your computer and use it in GitHub Desktop.
Laravel Cloud Navigation in Filament v4: Full tutorial and code https://silvanhagen.com/writing/laravel-cloud-navigation-in-filament/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Providers\Filament; | |
| // Other imports | |
| use function Filament\Support\original_request; | |
| class AdminPanelProvider extends PanelProvider | |
| { | |
| public function panel(Panel $panel): Panel | |
| { | |
| return $panel | |
| // Other methods | |
| ->tenant(Team::class) | |
| ->topNavigation() | |
| ->topbarLivewireComponent(CustomTopbar::class) | |
| ->viteTheme('resources/css/filament/admin/theme.css') | |
| ->navigation(function (NavigationBuilder $builder): NavigationBuilder { | |
| $tenant = Filament::getTenant(); | |
| $catalogs = $tenant->catalogs; | |
| $builder->groups( | |
| [ | |
| NavigationGroup::make('Catalogs') | |
| ->items( | |
| $catalogs | |
| ->map( | |
| fn (Catalog $catalog): NavigationItem => NavigationItem::make($catalog->name) | |
| ->icon(Heroicon::DocumentCheck) | |
| ->url(CatalogResource::getUrl()) | |
| ->isActiveWhen(fn (): bool => original_request()->route('catalog') == $catalog->id) | |
| )->toArray() | |
| ), | |
| ...$catalogs | |
| ->filter(fn (Catalog $catalog): bool => original_request()->route('catalog') == $catalog->id) | |
| ->map(fn (Catalog $catalog): NavigationGroup => NavigationGroup::make($catalog->name) | |
| ->items([ | |
| NavigationItem::make(LinkResource::getNavigationLabel()) | |
| ->icon(fn (): string|BackedEnum|Htmlable|null => LinkResource::getNavigationIcon()) | |
| ->url( | |
| LinkResource::getUrl( | |
| name: 'index', | |
| parameters: ['tenant' => $catalog->team_id, 'catalog' => $catalog->id] | |
| )) | |
| ->isActiveWhen(fn (): bool => original_request()->routeIs('filament.admin.resources.catalogs.links.*') | |
| && original_request()->route('catalog') == $catalog->id | |
| ) | |
| ->badge(fn () => original_request()->routeIs('filament.admin.resources.catalogs.*') | |
| && original_request()->route('catalog') == $catalog->id | |
| ? Cache::flexible( | |
| key: 'links_count:'.$catalog->id, | |
| ttl: [10, 60], | |
| callback: fn () => $catalog->loadCount('links')->links_count | |
| ) | |
| : null | |
| ), | |
| ]) | |
| ->collapsed() | |
| )->toArray(), | |
| ], | |
| ); | |
| return $builder; | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment