This plugin for Filament provides a Navigation resource that allows to build structural navigation menus with ease.
Begin by installing this package via Composer:
composer require ryangjchandler/filament-navigationThis plugin support classical or Orbit database driver. Orbit is installed by default.
By default, it uses classical driver. So if you use this plugin with MySQL, Postgresql, etc. you don't nothing to do more.
If you want to use it with Orbit, you just have to add a key to you .env file :
FILAMENT_NAVIGATION_DB_ENGINE=orbitIf you want you can publish the model specifically for the driver you use :
- For classical databse driver like MySQL, Postgresql etc. :
php artisan vendor:publish --tag="filament-navigation-model-classical" --force- If you prefer to use Orbit :
php artisan vendor:publish --tag="filament-navigation-model-with-orbit" --forcePublish the package's assets:
php artisan vendor:publish --tag="filament-navigation-assets"The NavigationResource is automatically registered with Filament so no configuration is required to start using it.
If you wish to customise the navigation group, sort or icon, you can use the respective NavigationResource::navigationGroup(), NavigationResource::navigationSort() and NavigationResource::navigationIcon() methods.
Each navigation menu is required to have a name and handle. The handle should be unique and used to retrieve the menu.
Items are stored inside of a JSON column called items. This is a recursive data structure that looks like:
[
{
"label": "Home",
"type": "external-link",
"data": {
"url": "/",
"target": "_blank",
},
"children": [
// ...
],
}
]The recursive structure makes it really simple to render nested menus / dropdowns:
<ul>
@foreach($menu->items as $item)
<li>
{{ $item['label'] }}
@if($item['children'])
<ul>
{{-- Render the item's children here... --}}
</ul>
@endforeach
</li>
@endforeach
</ul>To retreive a navigation object, provide the handle to the RyanChandler\FilamentNavigation\Facades\FilamentNavigation::get() method.
use RyanChandler\FilamentNavigation\Facades\FilamentNavigation;
$menu = FilamentNavigation::get('main-menu');Out of the box, this plugin comes with a single "item type" called "External link". This item type expects a URL to be provided and an optional "target" (same tab or new tab).
It's possible to extend the plugin with custom item types. Custom item types have a name and an array of Filament field objects that will be displayed inside of the "Item" modal.
This API allows you to deeply integrate navigation menus with your application's own entities and models.
use RyanChandler\FilamentNavigation\Facades\FilamentNavigation;
FilamentNavigation::addItemType('Post link', [
Select::make('post_id')
->searchable()
->options(function () {
return Post::pluck('title', 'id');
})
]);All custom fields for the item type can be found inside of the data property on the item.
This plugin also provides a custom Filament field that can be used to search and select a navigation menu inside other forms and resources.
use RyanChandler\FilamentNavigation\Filament\Fields\NavigationSelect;
->schema([
NavigationSelect::make('navigation_id'),
])By default, this field will not be searchable and the value for each option will be the menu id.
To make the field searchable, call the ->searchable() method.
->schema([
NavigationSelect::make('navigation_id')
->searchable(),
])If you wish to change the value for each option, call the ->optionValue() method.
->schema([
NavigationSelect::make('navigation_id')
->optionValue('handle'),
])composer testPlease 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.