This Filament package allows you to create and manage menus in your Filament application.
Note
I created this for my personal project, so some features and extensibility are still lacking. Pull requests are welcome.
You can install the package via composer:
composer require datlechin/filament-menu-builder
You need to publish the migrations and run them:
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, if you want to customize the views, you can publish them with:
php artisan vendor:publish --tag="filament-menu-builder-views"
This is the contents of the published config file:
return [
'tables' => [
'menus' => 'menus',
'menu_items' => 'menu_items',
'menu_locations' => 'menu_locations',
],
];
Add the plugin to AdminPanelProvider
:
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
$panel
...
->plugin(FilamentMenuBuilderPlugin::make())
Locations are the places where you can display menus in the frontend. You can add locations in the AdminPanelProvider
:
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->addLocation('header', 'Header')
->addLocation('footer', 'Footer')
)
The first argument is the key of the location, and the second argument is the title of the location.
Menu panels are the panels that contain the menu items which you can add to the menus.
By default, the package provides a Custom Link menu panel that allows you to add custom links to the menus.
The static menu panel allows you to add menu items manually.
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Datlechin\FilamentMenuBuilder\MenuPanel\StaticMenuPanel;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->addMenuPanels([
StaticMenuPanel::make()
->add('Home', url('/'))
->add('Blog', url('/blog')),
])
)
The model menu panel allows you to add menu items from a model.
To create a model menu panel, your model must implement the \Datlechin\FilamentMenuBuilder\Contracts\MenuPanelable
interface and \Datlechin\FilamentMenuBuilder\Concerns\HasMenuPanel
trait.
Then you will need to implement the following methods:
use Illuminate\Database\Eloquent\Model;
use Datlechin\FilamentMenuBuilder\Contracts\MenuPanelable;
class Category extends Model implements MenuPanelable
{
public function getMenuPanelTitleColumn(): string
{
return 'name';
}
public function getMenuPanelUrlUsing(): callable
{
return fn(self $model) => route('categories.show', $model->slug);
}
}
Then you can add the model menu panel to the plugin:
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Datlechin\FilamentMenuBuilder\MenuPanel\ModelMenuPanel;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->addMenuPanels([
ModelMenuPanel::make()
->model(\App\Models\Category::class),
])
)
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.