PHP code example of syriable / filament-menu-builder
1. Go to this page and download the library: Download syriable/filament-menu-builder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
syriable / filament-menu-builder example snippets
$menu = Menu::build('header'); // Collection of ResolvedMenuItem
use Syriable\Filament\Plugins\MenuBuilder\MenuBuilderPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
MenuBuilderPlugin::make()
->navigationGroup('Content') // optional
->navigationSort(10) // optional
->navigationIcon('heroicon-o-bars-3') // optional
->navigationLabel('Menus') // optional
->navigation(true) // set to false to hide the navigation item
->locales(['en', 'ar']) // optional, overrides config('menu-builder.locales')
->slideOver(true) // optional, overrides config('menu-builder.item_form.slide_over')
->modalWidth('2xl'), // optional, overrides config('menu-builder.item_form.width')
);
}
'item_form' => [
'slide_over' => true, // false: a centered modal
'width' => '2xl', // xs, sm, md, lg, xl, 2xl, 3xl, 4xl, 5xl, 6xl, 7xl, full or screen
],
use Syriable\Filament\Plugins\MenuBuilder\Facades\Menu;
use Syriable\Filament\Plugins\MenuBuilder\MenuPlacement;
public function boot(): void
{
Menu::registerPlacement(
MenuPlacement::make('header')
->label('Header')
->icon('heroicon-o-bars-3'),
MenuPlacement::make('footer')
->label('Footer')
->description('Links at the bottom of every page')
->icon('heroicon-o-rectangle-group')
->maxDepth(2)
->rootItemTypes(['heading']) // only headings at the top level
->childItemTypes('heading', ['link']) // headings contain links
->childItemTypes('link', []), // links have no children
MenuPlacement::make('sidebar')
->label('Sidebar')
->maxDepth(3)
->sort(30),
);
}
use Filament\Forms\Components\TextInput;
use Syriable\Filament\Plugins\MenuBuilder\MenuItemType;
Menu::registerItemType(
MenuItemType::make('page')
->label('Page')
->icon('heroicon-o-document')
->schema([ // Filament components, bound to `data`
TextInput::make('slug')->
MenuItemType::make('divider')
->withoutUrl() // not a link, like the built-in heading
->canHaveChildren(false); // never allows child items, in any placement
use Syriable\Filament\Plugins\MenuBuilder\Facades\Menu;
$items = Menu::build('header'); // current user and current URL
$items = Menu::build('header', $user); // a specific user
$items = Menu::build('header', currentUrl: $url);
$items = Menu::build('header', locale: 'ar'); // labels in another locale (default: app()->getLocale())
use Syriable\Filament\Plugins\MenuBuilder\MegaMenu;
public function boot(): void
{
MegaMenu::register(); // placement "categories"
}
MegaMenu::register('services', fn (MenuPlacement $placement) => $placement
->label('Service categories')
->childItemTypes('heading', ['link', 'category'])); // also allow a model-backed type in groups