PHP code example of doc88 / flux-menu-control

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

    

doc88 / flux-menu-control example snippets

 
    composer 
     
    'providers' => [
        ...
        Doc88\FluxMenuControl\FluxMenuControlServiceProvider::class,
    ]
 
    php artisan vendor:publish
 
    php artisan migrate
     
    use Doc88\FluxMenuControl\Traits\MenuMount;

    class User {
        use MenuMount;
    }

    // Create a new Menu Item
    Menu::create([
        'module' => 'Label of Menu Item', // al,
        'parent' => 'parent-menu-item-slug' // optional
    ]);

    // Return (array):
    [
        'module'    => 'Label of Menu Item',
        'slug'      => 'menu-slug',
        'icon'      => null,
        'parent_id' => null
    ]

    // Remove a Menu Item
    Menu::remove('menu-slug');

    // Return (bool)
    true or false

    // Attaching list-users permissions to menu-slug menu
    Menu::attachPermission('menu-slug', 'list-users');

    // Return (bool)
    true or false

    // Dettaching list-users permissions to menu-slug menu
    Menu::dettachPermission('menu-slug', 'list-users');

    // Return (bool)
    true or false

    // Synchronizing 
    Menu::sync($user);

    // Return (array)
    [
        [
            "module" => "Label of Menu Item",
            "slug" => "menu-slug",
            "icon" => null,
        ],
    ],

    // Getting user's menu
    Menu::get($user);

    // Return (array)
    [
        [
            "module" => "Label of Menu Item",
            "slug" => "menu-slug",
            "icon" => null,
        ],
    ],

    $user = User::find(1);
    
    // User's Permissions
    $user->getMenu();

    // Return (array):
    [
        [
            "module" => "Label of Menu Item",
            "slug" => "menu-slug",
            "icon" => null,
        ],
    ],