PHP code example of jrbconsulting / filament-menu-builder

1. Go to this page and download the library: Download jrbconsulting/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/ */

    

jrbconsulting / filament-menu-builder example snippets


use Vendor\FilamentMenuBuilder\Resources\MenuResource;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->resources([
            MenuResource::class,
            // ...
        ]);
}

// Get all active menus as tree
$menuTree = \Vendor\FilamentMenuBuilder\Models\Menu::getTree();

// Get root menus only
$rootMenus = \Vendor\FilamentMenuBuilder\Models\Menu::root()->active()->get();

// Get children of specific parent
$submenus = \Vendor\FilamentMenuBuilder\Models\Menu::where('parent_id', $parentId)->get();

// Get menu with depth calculation
$menu = \Vendor\FilamentMenuBuilder\Models\Menu::find(1);
$depth = $menu->calculateDepth(); // Number of ancestors

return [
    // Model class used for menus
    'model' => \Vendor\FilamentMenuBuilder\Models\Menu::class,
    
    // Database table name
    'table_name' => 'menus',
    
    // Enable multi-tenant mode
    'tenant_aware' => false,
    
    // Enable menu tree caching
    'cache_enabled' => true,
    
    // Cache duration in seconds
    'cache_duration' => 3600,
];

Schema::create('menus', function (Blueprint $table) {
    $table->id();
    $table->foreignId('tenant_id')->constrained(); // Add tenant relation
    $table->foreignId('parent_id')->nullable()->constrained('menus');
    $table->string('name');
    $table->string('url')->nullable();
    $table->string('target', 20)->nullable();
    $table->string('icon')->nullable();
    $table->integer('order')->default(0);
    $table->boolean('is_active')->default(true);
    $table->boolean('is_external')->default(false);
    $table->timestamps();
});

use Vendor\FilamentMenuBuilder\Resources\MenuResource;

MenuResource::setIcons([
    'custom-icon' => 'Custom Label',
    'heroicon-o-star' => 'Star',
]);
bash
php artisan vendor:publish --tag=filament-menu-builder-config
bash
php artisan vendor:publish --tag=filament-menu-builder-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=filament-menu-builder-views
bash
php artisan vendor:publish --tag=filament-menu-builder-views