PHP code example of rspeekenbrink / laravel-menu

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

    

rspeekenbrink / laravel-menu example snippets


Menu::add('itemName', '/');


// Menu::toArray() Output:
[
    [
        'name' => 'itemName',
        'route' => '/',
        'active' => true,
    ]
]

Menu::add('dashboard', '/')->addChildren(function () {
    Menu::add('stats', '/stats');
    Menu::add('profile', '/profile');
});

// Menu::toArray() Output:
[
    [
        'name' => 'dashboard',
        'route' => '/',
        'active' => true,
        'children' => [
            [
                'name' => 'dashboard.stats',
                'route' => '/stats',
                'active' => false,
            ],
            [
                'name' => 'dashboard.profile',
                'route' => '/profile',
                'active' => false,
            ]
        ]
    ]
]

Menu::add('itemName', '/', ['title' => 'Dashboard', 'someAttribute' => 231, 'another' => 'value2']);


// Menu::toArray() Output:
[
    [
        'name' => 'itemName',
        'route' => '/',
        'active' => true,
        'title' => 'Dashboard',
        'someAttribute' => 231,
        'another' => 'value2,
    ]
]

Menu::addIf($conditionOrClosure, 'itemName', $route, $attributes);

Menu::addIfCan('MyAuthGuard', 'itemName', $route, $attributes);

Inertia::share([
    'menu' => function () {
        return Menu::toArray();
    }
]);