1. Go to this page and download the library: Download konekt/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/ */
Menu::create('sidebar', null, ['share' => true]); // will be $sidebar in views
Menu::create('main', null, ['share' => 'mainMenu']); // will be $mainMenu in views
$navbar = Menu::create('navbar');
// Simple link; to '/' via the URL helper
$navbar->addItem('home', 'Home', '/');
// Named route
$navbar->addItem('clients', 'Clients', ['route' => 'client.index']);
// Named route with parameter
$navbar->addItem('my-profile', 'My Profile', ['route' => ['user.show', 'id' => Auth::user()->id]]);
// Refer to an action
$navbar->addItem('projects', 'Projects', ['action' => 'ProjectController@index']);
// Action with parameter
$navbar->addItem('issue7', 'Issue 7', ['action' => ['IssueController@edit', 'id' => 7]]);
$menu = Menu::create('main');
$menu->addItem('home', 'Home', '/');
$menu->addItem('about', 'About', '/about');
$menu->getItem('about')->addSubItem('about-us', 'About Us', ['url' => '/about/us']);
// This will remove both about and about-us
$menu->removeItem('about');
// To keep children, set the second parameter `$removeChildren` to false:
$menu->removeItem('about', false); // about-us will remain
$menu = Menu::create('uberGigaMenu')
$menu->addItem('about', 'About', ['route' => 'page.about']);
// these items will go under Item 'About'
// refer to about as a property of $menu object then call `addItem()` on it
$menu->about->addSubItem('who-we-are', 'Who We are', '/who-we-are');
// or
$menu->getItem('about')->addSubItem('what-we-do', 'What We Do', '/what-we-do');
// or
$menu->addItem('our-goals', 'Our Goals',[
'parent' => 'about',
'url' => '/our-goals'
]);
$menu->addItem('about', 'About');
// You can either set the item object directly as parent:
$menu->addItem('team', 'The Team', ['url' => '/about-the-team', 'parent' => $menu->about]);
// Or just simply the parent item's name:
$menu->addItem('board', 'The Board', ['url' => '/about-the-board', 'parent' => 'about']);
$menu = \Menu::create('menu');
$menu->addItem('contact', 'Contact', '/contact');
// via the getItem method:
$menu->getItem('contact');
// or via magic property accessor:
$menu->contact;
$about = $menu->addItem('about', 'About', '/about');
$about->addSubItem('who-we-are', 'Who We Are', '/about/who-we-are');
$about->addSubItem('what-we-do', 'What We Do', '/about/what-we-do');
$aboutSubs = $menu->about->children();
// or outside of the builder context
$aboutSubs = Menu::get('MyNavBar')->about->children();
// Or
$aboutSubs = Menu::get('MyNavBar')->getItem('about')->children();
if( $menu->about->hasChildren() ) {
// Do something
}
// or outside of the builder context
Menu::get('MyNavBar')->about->hasChildren();
// Or
Menu::get('MyNavBar')->getItem('about')->hasChildren();
$menu->addItem('Home', '#')->data('color', 'red');
$menu->addItem('About', '#')->data('color', 'blue');
$menu->addItem('Services', '#')->data('color', 'red');
$menu->addItem('Contact', '#')->data('color', 'green');
// Fetch all the items with color set to red:
$reds = $menu->whereColor('red');
$menu = Menu::get('MyNavBar');
$menus = Menu::all();
$menu = Menu::create('MyNavBar');
// As you see, you need to pass the second parameter as an associative array:
$menu->addItem('home', 'Home', ['route' => 'home.page', 'class' => 'navbar navbar-home', 'id' => 'home']);
$menu->addItem('about', 'About', ['route' => 'page.about', 'class' => 'navbar navbar-about dropdown']);
$menu->addItem('services', 'Services', ['action' => 'ServicesController@index']);
$menu->addItem('contact', 'Contact', 'contact');
$menu->addItem('About', 'about');
$menu->about->addSubItem('whoweare', 'Who we are', 'about/whoweare');
$menu->about->addSubItem('whatwedo', 'What we do', 'about/whatwedo');
// add a class to children of About
$menu->about->children()->attr('class', 'about-item');
// To prevent from auto activation
Menu::create('nav', [
'auto_activate' => false
]);
// To set the active element:
Menu::create('nav', [
'active_element' => 'link' // item|link - item by default
]);
$menu->addItem('users', 'Users');
$menu->users->addSubItem('create_user', 'New User', ['route' => 'user.create']);
$menu->users->addSubItem('list_users', 'Uses', ['route' => 'user.index']);
// add a meta data to children of Users
$menu->users->children()->data('tag', 'admin');
$menu->users->isAllowed(); // Checks if the item users item is allowed for the current user
$menu->settings->isAllowed(\App\User::find(501)); // Check if an item is available for a given user
$item->childrenAllowed(); // Returns an ItemCollection of the allowed item for the current user
$item->childrenAllowed(\App\User::find(123)); // Returns the allowed items for the given user
blade
{{-- Render with the built in 'ul' renderer --}}
{!! $mainMenu->render('ul') !!}
{{--Or render items manually--}}
<nav>
@foreach($mainMenu->items as $item)
<div class="nav-link><a href="{{ $item->url }}">{{ $item->title }}</a></div>
@endforeach
</nav>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.