lunestudio/filament-navigation-manager

A navigation manager for Filament projects.

0.1.2 2025-01-06 13:46 UTC

This package is auto-updated.

Last update: 2025-05-06 14:37:34 UTC


README

Latest Version on Packagist Total Downloads

A menu management plugin for Filament.

Installation

You can install the package via composer:

composer require lunestudio/filament-navigation-manager

Then run the installation command to publish migrations and assets:

php artisan filament-navigation-manager:install

After that, you will need to add a plugin to your AdminPanelProvider

public function panel(Panel $panel): Panel
{
    return $panel
        ->default()
        ->id('admin')
        ->path('admin')
        ->plugins([
            // ...$plugins,
            FilamentNavigationManagerPlugin::make(),
        ]);
}

To publish the config file, run:

php artisan vendor:publish --tag="filament-navigation-manager-config"

Here is the content of the published config file:

return [
    'model' => \Lunestudio\FilamentNavigationManager\Models\Menu::class,

    'resources' => [
        'label' => 'Menu',
        'plural_label' => 'Menus',
        'navigation_group' => null,
        'navigation_label' => 'Menus',
        'navigation_icon' => 'heroicon-o-list-bullet',
        'navigation_sort' => null,
        'navigation_count_badge' => false,
        'resource' => \Lunestudio\FilamentNavigationManager\Filament\Resources\MenuResource::class,
    ],

    'linkable' => [
        [
            'model' => \App\Models\User::class,
            'label' => __('Users'),
            'model_prop_to_pluck' => 'name',
            'item_prop_to_text' => 'name',
            'route_name' => 'user',
            'model_prop_to_route' => 'email',
        ],
        // [
        //     'model' => $full_class_name,
        //     'label' => $text_label_to_linkable_type_select,
        //     'model_prop_to_pluck' => $fillable_name,
        //     'item_prop_to_text' => $fillable_name,
        //     'route_name' => $route_name,
        //     'model_prop_to_route' => $fillable_name_and_route_attr,
        // ],
    ],
];

Linkable items must consider the properties of the models and the attributes of the routes.

The properties model_prop_to_pluck, item_prop_to_text, and model_prop_to_route must be fillable.

At the same time, the model_prop_to_route property must be defined with the same name as the model property, and the route must be named.

An example for the linkable User is:

Route::get('/users/{email}', function () {
    return view('dashboard');
})->name('user');

And in the model:

class User extends Authenticatable
{
    protected $fillable = [
        'name',
        'email',
    ];
}

Menu Resource

This is the index page for creating menus.

Menu Resource

You can define the following properties: Name, Location, Append profile item and Keep on mobile.

Edit Menu

You can also add menu items and define: Parent Item, Linkable Type, Linkable Id, Custom Link, Ícon, Name, Extra Classes and Link Target.

Add Item

Afterward, you can reorder items by dragging and dropping them.

Reorder Items

Menu Blade Component

To make it as easy as possible to output your menu, Lunestudio provides an <x-navigation-manager::menu> blade component.

The default location is main, but you can change it to any registered menu location.

<x-navigation-manager::menu />
<x-navigation-manager::menu menu-location="footer" />

This is the default view

Menu View

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.