Originally forked from harimayco/wmenu-builder, but under active maintenance.
composer require efectn/laravel-menu-builder
'Menu' => Efectn\Menu\Facades\Menu::class,
php artisan vendor:publish --provider="Efectn\Menu\MenuServiceProvider"
php artisan migrate
DONE
On your view blade file
@extends('app')
@section('contents')
{!! Menu::render() !!}
@endsection
//YOU MUST HAVE JQUERY LOADED BEFORE menu scripts
@push('scripts')
{!! Menu::scripts() !!}
@endpush
Call the model class
use Efectn\Menu\Models\Menus;
use Efectn\Menu\Models\MenuItems;
A basic two-level menu can be displayed in your blade template
/* get menu by id*/
$menu = Menus::find(1);
/* or by name */
$menu = Menus::where('name','Test Menu')->first();
/* or get menu by name and the items with EAGER LOADING (RECOMENDED for better performance and less query call)*/
$menu = Menus::where('name','Test Menu')->with('items')->first();
/*or by id */
$menu = Menus::where('id', 1)->with('items')->first();
//you can access by model result
$public_menu = $menu->items;
//or you can convert it to array
$public_menu = $menu->items->toArray();
// Using Helper
$public_menu = Menu::getByName('Public'); //return array
Now inside your blade template file place the menu using this simple example
<div class="nav-wrap">
<div class="btn-menu">
<span></span>
</div><!-- //mobile menu button -->
<nav id="mainnav" class="mainnav">
@if($public_menu)
<ul class="menu">
@foreach($public_menu as $menu)
<li class="">
<a href="https://github.com/efectn/laravel-menu-builder/blob/master/{{ $menu['link'] }}" title="">{{ $menu['label'] }}</a>
@if( $menu['child'] )
<ul class="sub-menu">
@foreach( $menu['child'] as $child )
<li class=""><a href="https://github.com/efectn/laravel-menu-builder/blob/master/{{ $child['link'] }}" title="">{{ $child['label'] }}</a></li>
@endforeach
</ul><!-- /.sub-menu -->
@endif
</li>
@endforeach
@endif
</ul><!-- /.menu -->
</nav><!-- /#mainnav -->
</div><!-- /.nav-wrap -->
use Efectn\Menu\Facades\Menu;
...
/*
Parameter: Menu ID
Return: Array
*/
$menuList = Menu::get(1);
In this example, you must have a menu named Admin
use Efectn\Menu\Facades\Menu;
...
/*
Parameter: Menu ID
Return: Array
*/
$menuList = Menu::getByName('Admin');
you can edit the menu interface in resources/views/vendor/menu-builder/menu-html.blade.php
Note: Look at https://github.com/efectn/laravel-menu-builder/issues/1.