| Install | |
|---|---|
composer require ycookies/filament-nav-manager |
|
| Latest Version: | 1.0.5-beta1 |
| PHP: | ^8.2 |
A powerful navigation management package for Filament v4 that allows you to dynamically manage your Filament panel navigation menus through a user-friendly interface.
✨ Rich Feature Set
You can install the package via Composer:
composer require ycookies/filament-nav-manager
php artisan filament-nav-manager:install
This command will:
Or manually:
php artisan vendor:publish --tag="filament-nav-manager-migrations"
php artisan migrate
php artisan vendor:publish --tag="filament-nav-manager-config"
Add the plugin to your Filament panel provider:
use Ycookies\FilamentNavManager\FilamentNavManagerPlugin;
use Ycookies\FilamentNavManager\Models\NavManager;
public function panel(Panel $panel): Panel
{
return $panel
->plugin(FilamentNavManagerPlugin::make())
->navigation(
NavManager::generate()
->panel($panel->getId())
->cacheTime(config('nav-manager.cache_seconds', 0))
->toClosure()
);
}
Edit config/nav-manager.php:
return [
// Allow specific roles to access Nav Manager
'allowed_roles' => ['admin', 'super_admin'], // or null for all authenticated users
// Cache navigation for better performance (in seconds)
'cache_seconds' => 3600, // 0 to disable caching
// Database table name
'table_name' => 'nav_manager',
// Navigation group for Nav Manager resource in sidebar
'navigation_group' => null, // null to use translation, or custom name like 'System', 'Settings'
];
You can customize which navigation group the Nav Manager resource appears in:
// config/nav-manager.php
return [
'navigation_group' => 'System Settings', // Custom group name
// or
'navigation_group' => null, // Use default translation
];
Sync a specific panel:
php artisan filament-nav-manager:sync admin
Or sync all panels during installation:
php artisan filament-nav-manager:install
Once installed, you'll see "Navigation Manager" in your Filament navigation. From there you can:
The package supports several navigation item types:
Navigation items are organized in a hierarchical tree structure:
Navigation Group
├── Resource Item
├── Page Item
└── Navigation Group
├── Resource Item
└── Route Item
You can also manage navigation programmatically:
use Ycookies\FilamentNavManager\Models\NavManager;
// Create a navigation item
NavManager::create([
'title' => 'My Menu',
'type' => NavManager::TYPE_RESOURCE,
'target' => \App\Filament\Resources\Users\UserResource::class,
'panel' => 'admin',
'parent_id' => 0,
'order' => 1,
'show' => true,
'icon' => 'heroicon-o-users',
]);
// Sync panel resources and pages
$panel = Filament::getPanel('admin');
$count = NavManager::syncPanel($panel);
// Clear navigation cache
NavManager::flushNavigationCache('admin');
use Ycookies\FilamentNavManager\Models\NavManager;
// Generate navigation for a specific panel
$navigation = NavManager::navigationForPanel('admin', cacheSeconds: 3600);
// Use in panel configuration
$panel->navigation(
NavManager::generate()
->panel('admin')
->cacheTime(3600)
->toClosure()
);
The package includes translations for:
en)zh_CN)zh_TW)Translations are automatically loaded. Set your application locale:
config(['app.locale' => 'zh_CN']);
Configure which roles can access the Navigation Manager:
// config/nav-manager.php
return [
'allowed_roles' => ['admin', 'super_admin'],
];
If using Spatie Laravel Permission:
// The package automatically checks if user has any of the allowed roles
'allowed_roles' => ['admin', 'super_admin'],
Set to null to allow all authenticated users:
'allowed_roles' => null, // All authenticated users can access
If your application has a treeView table macro (commonly used for hierarchical data), the navigation table will automatically use it for a better tree-structured display.
use Ycookies\FilamentNavManager\NavManagerNavigationGenerator;
// Clear cache for current panel
NavManagerNavigationGenerator::flush();
// Clear cache for specific panel
NavManagerNavigationGenerator::flush('admin');
Or via model:
use Ycookies\FilamentNavManager\Models\NavManager;
NavManager::flushNavigationCache('admin');
The package creates a nav_manager table with the following structure:
id - Primary keyparent_id - Parent menu item ID (0 for top-level)panel - Filament panel IDorder - Display ordertitle - Menu titletype - Menu type (group, resource, page, route, url)icon - Heroicon nameuri - URI pathtarget - Resource class, Page class, or route nameextension - Extension identifiershow - Visibility togglebadge - Badge textbadge_color - Badge coloris_collapsed - Collapsed statepermission - Required permissioncreated_at / updated_at - Timestampsphp artisan filament-nav-manager:install
Runs migrations and optionally syncs panels.
php artisan filament-nav-manager:sync {panel}
Syncs Filament resources and pages for a specific panel.
show = trueNavManager::flushNavigationCache()config/nav-manager.php for allowed_roles configurationContributions are welcome! Please feel free to submit a Pull Request.
The MIT License (MIT). Please see License File for more information.
Please see CHANGELOG for more information on what has changed recently.
Made with ❤️ by eRic