ycookies / filament-nav-manager
A powerful navigation management package for Filament v4 that allows you to dynamically manage your Filament panel navigation menus
Fund package maintenance!
ycookies
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ycookies/filament-nav-manager
Requires
- php: ^8.2
- filament/filament: ^4.0
- guava/filament-icon-picker: ^3.0
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.1
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
README
A powerful navigation management package for Filament v4 that allows you to dynamically manage your Filament panel navigation menus through a user-friendly interface.
Features
⨠Rich Feature Set
- đ¯ Dynamic navigation management through Filament UI
- đ Automatic synchronization of Filament resources and pages
- đŗ Tree-structured menu hierarchy support
- đ¨ Customizable navigation groups, icons, and badges
- đ Role-based access control
- đ Multi-language support (English, Simplified Chinese, Traditional Chinese)
- ⥠Navigation caching for better performance
- đĻ Easy installation and setup
Installation
You can install the package via Composer:
composer require ycookies/filament-nav-manager
Publish and Run Migrations
php artisan filament-nav-manager:install
This command will:
- Publish the configuration file
- Publish migration files
- Ask if you want to run migrations
- Allow you to sync panels
Or manually:
php artisan vendor:publish --tag="filament-nav-manager-migrations" php artisan migrate php artisan vendor:publish --tag="filament-nav-manager-config"
Configuration
Enable the Plugin
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() ); }
Configure Permissions
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' ];
Customize Navigation Group
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 ];
Usage
Syncing Filament Resources and Pages
Option 1: Via UI
- Navigate to "Navigation Manager" in your Filament panel
- Click the "Sync Filament Menu" button
- Confirm the sync operation
Option 2: Via Command Line
Sync a specific panel:
php artisan filament-nav-manager:sync admin
Or sync all panels during installation:
php artisan filament-nav-manager:install
Managing Navigation Items
Once installed, you'll see "Navigation Manager" in your Filament navigation. From there you can:
- â Create new navigation items
- â Edit existing items
- â Delete items
- â Reorder items (drag and drop if tree view is enabled)
- â Toggle visibility
- â Manage icons and badges
- â Set permissions
Navigation Item Types
The package supports several navigation item types:
- Group - A navigation group that can contain child items
- Resource - Links to a Filament resource
- Page - Links to a Filament page
- Route - Links to a Laravel route
- URL - Links to any URL (internal or external)
Navigation Structure
Navigation items are organized in a hierarchical tree structure:
Navigation Group
âââ Resource Item
âââ Page Item
âââ Navigation Group
âââ Resource Item
âââ Route Item
Advanced Usage
Programmatic Navigation Management
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');
Custom Navigation Generation
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() );
Multi-Language Support
The package includes translations for:
- đŦđ§ English (
en) - đ¨đŗ Simplified Chinese (
zh_CN) - đšđŧ Traditional Chinese (
zh_TW)
Translations are automatically loaded. Set your application locale:
config(['app.locale' => 'zh_CN']);
Role-Based Access Control
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
Tree View Support
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.
Clearing Navigation Cache
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');
Database Schema
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- Timestamps
Commands
Install Command
php artisan filament-nav-manager:install
Runs migrations and optionally syncs panels.
Sync Command
php artisan filament-nav-manager:sync {panel}
Syncs Filament resources and pages for a specific panel.
Troubleshooting
Navigation Not Appearing
- Ensure the plugin is registered in your Panel Provider
- Check that navigation items have
show = true - Verify user has required roles (if configured)
- Clear navigation cache:
NavManager::flushNavigationCache()
Sync Not Working
- Verify the panel ID exists
- Check that resources/pages are properly registered in the panel
- Review error logs for specific issues
Permission Issues
- Check
config/nav-manager.phpforallowed_rolesconfiguration - Verify user roles are correctly assigned
- Ensure Spatie Laravel Permission is installed if using roles
Requirements
- PHP >= 8.2
- Laravel >= 10.0
- Filament >= 4.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.
Support
- đ§ Email: 3664839@qq.com
- đ Issues: GitHub Issues
- đ Documentation: GitHub Wiki
Changelog
Please see CHANGELOG for more information on what has changed recently.
Made with â¤ī¸ by eRic