PHP code example of rc1021 / laravel-menu-architect

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

    

rc1021 / laravel-menu-architect example snippets


'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,

    ...

        Rc1021\LaravelMenuArchitect\LaravelMenuArchitectServiceProvider::class,

        ...

],

'aliases' => [

    'App'       => Illuminate\Support\Facades\App::class,
    'Artisan'   => Illuminate\Support\Facades\Artisan::class,
    ...
    'MenuArct'      => Rc1021\LaravelMenuArchitect\Facades\MenuArct::class,

],

{!! menu_arct('admin') !!}

$arr_menu = menu_arct('admin', '_array');
$json_menu = menu_arct('admin', '_json');
 
$customize_func = function ($menu) 
{
    // $menu: main menu modal.
    // $menu->items: items by menu_id.
    // $menu->buildTree(): get a hierarchical array data.(parent, children)

    $collection = collect($menu->items);
    $filtered = $collection->filter(function ($item, $key) {
        return $item['depth'] == 2 and isset($item['children']);
    });
    return $filtered->all();
}

$customize_data = menu_arct('admin', 'key', ['key' => $customize_func]);

// your_view.blade.php

// $menu: main menu modal
// $menu->items: items by menu_id
// $items: Hierarchical array data(parent, children)

<ul class="sidebar-menu tree" data-widget="tree">
    @foreach ($items as $item)
        <li class="header {{$item['class']}}" style="{{empty($item['color'])?:'color:'.$item['color']}}">{{$item['label']}}</li>
        @if(isset($item['children']))
            @each('menu_architect::menu.display.adminlte_list', $item['children'], 'item')
        @endif
    @endforeach
</ul>
bash
php artisan vendor:publish --provider="Rc1021\\LaravelMenuArchitect\\LaravelMenuArchitectServiceProvider"
bash
php artisan serve
bash
php artisan db:seed --class=MenuArchitectSeeder