Skip to content

Biostate/filament-menu-builder

Repository files navigation

An Elegant Menu Builder for Filament

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Note: I developed this package as a hobby project, but wanted to share it with whoever may need it. I will keep updating this package. If you have any suggestions, feel free to create an issue.

This package offers a powerful menu builder for the Filament admin panel, enabling efficient menu creation and management.

  • Integrate models and routes into menu items for dynamic and flexible navigation.
  • Render menus with Blade components for consistency and adaptability.

Built for simplicity and performance, this package ensures a seamless solution for managing menus in the Filament admin panel.

Dark Theme Light Theme

Table of Contents:

Installation

You can install the package via composer:

composer require biostate/filament-menu-builder

Add the plugin to your AdminPanelServiceProvider.php:

public function panel(Panel $panel): Panel
{
    return $panel
        // Your other configurations
        ->plugins([
            \Biostate\FilamentMenuBuilder\FilamentMenuBuilderPlugin::make(), // Add this line
        ]);
}

You can publish and run the migrations with:

php artisan vendor:publish --tag="filament-menu-builder-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="filament-menu-builder-config"

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-menu-builder-views"

Caching

Menu items are cached in view component by default. If you want to disable caching, you can set the cache configuration to false.

Menuable Trait

You can create relationships between menu items and your models. To enable this feature, you need to add the Menuable trait to your model and implement the getMenuLinkAttribute method. If you want to use the model name as the menu item name, you can use the getMenuNameAttribute method.

use Biostate\FilamentMenuBuilder\Traits\Menuable;

class Product extends Model
{
    use Menuable;
    
    public function getMenuLinkAttribute(): string
    {
        return route('products.show', $this);
    }
    
    public function getMenuNameAttribute(): string
    {
        return $this->name;
    }
}

After this you need to add your model in to the config file. You can add multiple models. eg:

return [
    'models' => [
        'Product' => \App\Models\Product::class,
    ],
];

If you add these configurations, you can see the menu items in the menu item forms as a select input.

Routes

You can use your routes in the menu items. But if you want to exclude some routes, you can use the exclude_route_names configuration. Package excludes the debugbar routes, filament routes, and livewire routes in default.

'exclude_route_names' => [
    '/^debugbar\./', // Exclude debugbar routes
    '/^filament\./',   // Exclude filament routes
    '/^livewire\./',   // Exclude livewire routes
],

Blade Components

This package provides some blade components to render the menu items. You can use these components in your blade files. You can get this code in the menus table. For example:

<x-filament-menu-builder::menu slug="main-menu" />

This blade component will render the menu items with the main-menu slug. You can also publish the views and customize the blade components.

Also you can give a custom view to the component. This package supports Bootstrap 5 by default. For example:

<x-filament-menu-builder::menu slug="main-menu" view="filament-menu-builder::components.bootstrap5.menu"/>

TODO

  • add parameters like mega menu, dropdown, etc.
  • add tests
  • add tailwind blade component
  • add "Do you want to discard the changes?" if you have unsaved changes
  • add more actions like: move up, move down, move one level up, move one level down, etc.

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

About

An Elegant Menu Builder for FilamentPHP

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published