1. Go to this page and download the library: Download gaba93/laravel-menu-updated 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/ */
// Suppose we have these routes defined in our app/routes.php file
//...
Route::get('/', array('as' => 'home.page', function(){...}));
Route::get('about', array('as' => 'page.about', function(){...}));
//...
// Now we make the menu:
Menu::make('MyNavBar', function($menu){
$menu->add('Home', array('route' => 'home.page'));
$menu->add('About', array('route' => 'page.about'));
// ...
});
// Suppose we have these routes defined in our app/Http/routes.php file
// ...
Route::get('services', 'ServiceController@index');
//...
// ...
$menu->add('services', array('action' => 'ServicesController@index'));
// ...
// ...
$menu->add('Members', 'members')->link->secure();
// or alternatively use the following method
$menu->add('Members', array('url' => 'members', 'secure' => true));
// ...
Menu::make('MyNavBar', function($menu){
//...
$menu->add('About', array('route' => 'page.about'));
// these items will go under Item 'About'
// refer to about as a property of $menu object then call `add()` on it
$menu->about->add('Who We are', 'who-we-are');
// or
$menu->get('about')->add('What We Do', 'what-we-do');
// or
$menu->item('about')->add('Our Goals', 'our-goals');
//...
});
// ...
$menu->add('About', array('route' => 'page.about'))
->nickname('about_menu_nickname');
// And use it like you normally would
$menu->item('about_menu_nickname');
// ...
// ...
$menu->add('About', array('route' => 'page.about', 'nickname' => 'about_menu_nickname'));
// And use it like you normally would
$menu->item('about_menu_nickname');
// ...
// ...
$menu->itemTitleInCamelCase ...
// or
$menu->get('itemTitleInCamelCase') ...
// or
$menu->item('itemTitleInCamelCase') ...
// ...
// ...
$menu->add('About us', 'about-us')
$menu->aboutUs->divide();
// or
$menu->get('aboutUs')->divide();
// or
$menu->item('aboutUs')->divide();
// ...
// ...
$about = $menu->add('About', 'about');
$about->add('Who We Are', 'who-we-are');
$about->add('What We Do', 'what-we-do');
// ...
// ...
$menu->find(12) ...
// ...
// ...
$menu->all();
// or outside of the builder context
Menu::get('MyNavBar')->all();
// ...
// ...
$menu->first();
// or outside of the builder context
Menu::get('MyNavBar')->first();
// ...
// ...
$menu->last();
// or outside of the builder context
Menu::get('MyNavBar')->last();
// ...
// ...
$aboutSubs = $menu->about->children();
// or outside of the builder context
$aboutSubs = Menu::get('MyNavBar')->about->children();
// Or
$aboutSubs = Menu::get('MyNavBar')->item('about')->children();
// ...
// ...
if( $menu->about->hasChildren() ) {
// Do something
}
// or outside of the builder context
Menu::get('MyNavBar')->about->hasChildren();
// Or
Menu::get('MyNavBar')->item('about')->hasChildren();
// ...
// ...
$aboutSubs = $menu->about->all();
// ...
// ...
$subs = $menu->whereParent(12);
// ...
// ...
$menu->add('Home', '#')->data('color', 'red');
$menu->add('About', '#')->data('color', 'blue');
$menu->add('Services', '#')->data('color', 'red');
$menu->add('Contact', '#')->data('color', 'green');
// ...
// Fetch all the items with color set to red:
$reds = $menu->whereColor('red');
$reds = $menu->whereColor('red', true);
// ...
$menu = Menu::get('MyNavBar');
// ...
// ...
$menus = Menu::all();
// ...
// ...
$menus = Menu::getCollection();
// ...
Menu::make('MyNavBar', function($menu){
// As you see, you need to pass the second parameter as an associative array:
$menu->add('Home', array('route' => 'home.page', 'class' => 'navbar navbar-home', 'id' => 'home'));
$menu->add('About', array('route' => 'page.about', 'class' => 'navbar navbar-about dropdown'));
$menu->add('services', array('action' => 'ServicesController@index'));
$menu->add('Contact', 'contact');
});
// ...
$menu->add('About', 'about');
$menu->about->add('Who we are', 'about/whoweare');
$menu->about->add('What we do', 'about/whatwedo');
// add a class to children of About
$menu->about->children()->attr('class', 'about-item');
// ...
//...
$menu->add('Separated Item', 'item-url')->divide()
// You can also use it this way:
$menu->('Another Separated Item', 'another-item-url');
// This line will insert a divider after the last defined item
$menu->divide()
//...
/*
Output as <ul>:
<ul>
...
<li><a href="item-url">Separated Item</a></li>
<li class="divider"></li>
<li><a href="another-item-url">Another Separated Item</a></li>
<li class="divider"></li>
...
</ul>
*/
//...
$menu->add('Users', '#')->data('placement', 12);
// you can refer to placement as if it's a public property of the item object
echo $menu->users->placement; // Output : 12
//...
// ...
$menu->add('Users', 'users');
$menu->users->add('New User', 'users/new');
$menu->users->add('Uses', 'users');
// add a meta data to children of Users
$menu->users->children()->data('anything', 'value');
// ...