PHP code example of i9w3b / laravel-menu-manager

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

    

i9w3b / laravel-menu-manager example snippets


php artisan vendor:publish --provider="Harimayco\Menu\MenuServiceProvider"

php artisan migrate

// arquivo config/menu.php
/*
|--------------------------------------------------------------------------
| Publicar rota para gerenciar (get e post) menus | true ou false
|--------------------------------------------------------------------------
*/
'routes_view' => false,
'routes_post' => false,

@extends('app')

@section('contents')
    {!! Menu::render() !!}
@endsection

@push('scripts')
    {!! Menu::scripts() !!}
@endpush

use Harimayco\Menu\Models\Menus;
use Harimayco\Menu\Models\MenuItems;

// Obter o menu por ID
$menu = Menus::find(1);

// Ou por nome
$menu = Menus::where('name','Test Menu')->first();

// Ou obtenha o menu pelo nome e os itens (RECOMENDADO para melhor desempenho e menos chamadas de consulta)
$menu = Menus::where('name','Test Menu')->with('items')->first();

// Ou acesse
$menu = Menus::where('id', 1)->with('items')->first();

// Acessar o resultado
$public_menu = $menu->items;

// Ou converta em array
$public_menu = $menu->items->toArray();

<div class="nav-wrap">
    <div class="btn-menu">
        <span></span>
    </div>
    <nav id="mainnav" class="mainnav">
        @if($public_menu)
        <ul class="menu">
            @foreach($public_menu as $menu)
            <li class="">
                <a href="{{ $menu['link'] }}" title="">{{ $menu['label'] }}</a>
                @if( $menu['child'] )
                <ul class="sub-menu">
                    @foreach( $menu['child'] as $child )
                        <li class=""><a href="{{ $child['link'] }}" title="">{{ $child['label'] }}</a></li>
                    @endforeach
                </ul>
                @endif
            </li>
            @endforeach
        @endif
        </ul>
    </nav>
 </div>

use Harimayco\Menu\Facades\Menu;

$menuList = Menu::get(1);

use Harimayco\Menu\Facades\Menu;

$menuList = Menu::getByName('Admin');

php artisan vendor:publish --provider="Harimayco\Menu\MenuServiceProvider"