PHP code example of ak-media / filament-menu-manager

1. Go to this page and download the library: Download ak-media/filament-menu-manager 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/ */

    

ak-media / filament-menu-manager example snippets


use NoteBrainsLab\FilamentMenuManager\FilamentMenuManagerPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(
            FilamentMenuManagerPlugin::make()
                ->locations([
                    'primary' => 'Primary',
                    'footer'  => 'Footer',
                ])
        );
}

FilamentMenuManagerPlugin::make()
    ->locations(['primary' => 'Primary', 'footer' => 'Footer'])
    ->modelSources([\App\Models\Post::class, \App\Models\Page::class])
    ->navigationGroup('Content')
    ->navigationIcon('heroicon-o-bars-3')
    ->navigationSort(10)
    ->navigationLabel('Menus');

use NoteBrainsLab\FilamentMenuManager\Concerns\HasMenuItems;

class Post extends Model
{
    use HasMenuItems;

    // Optional: override the defaults
    public function getMenuLabel(): string  { return $this->title; }
    public function getMenuUrl(): string    { return route('posts.show', $this); }
    public function getMenuTarget(): string { return '_self'; }
    public function getMenuIcon(): ?string  { return 'heroicon-o-document'; }
}

FilamentMenuManagerPlugin::make()
    ->modelSources([\App\Models\Post::class])
bash
php artisan filament-menu-manager:install
# or manually:
php artisan vendor:publish --tag="filament-menu-manager-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-menu-manager-config"
bash
php artisan vendor:publish --tag="filament-menu-manager-views"
blade
@php
    $manager = app(\NoteBrainsLab\FilamentMenuManager\MenuManager::class);
    $menus   = $manager->menusForLocation('primary');
    $menu    = $menus->first();
    $tree    = $menu?->getTree() ?? [];
@endphp

@foreach($tree as $item)
    <a href="{{ $item['url'] }}" target="{{ $item['target'] }}">{{ $item['title'] }}</a>
    @if(!empty($item['children']))
        {{-- render children --}}
    @endif
@endforeach