jminayat/modules-laravel is a package for the administration of menus in laravel. compatible with Laravel version 5.5., (*1)
Installation
Install the package through the composer.
``` bash
composer require jminayat/laravel-menu, (*2)
Next, publish the package configuration file by running:
``` bash
php artisan vendor:publish --provider="JMinayaT\Menus\MenusServiceProvider"
For the creation of a menu, call the creation method from Menu facade. The first parameter is the name of the menu and the second parameter is the callback to define the menu items., (*3)
Menu::create('test',function($menu){
$menu->link('home/1','Home',['icon'=>'icon-home']);
});
If you want to create multiple menus, (*4)
Menu::create('test1',function($menu){
$menu->link('home/1','Home',['icon'=>'icon-home']);
});
Menu::create('test2',function($menu){
$menu->link('user','user');
});
To create a link menu item use $menu->link(), (*5)
Menu::create('test',function($menu){
// 'url' 'title' 'attributes'
$menu->link('home/1','Home',['icon'=>'icon-home']);
});
If you have a rute element defined with your name, use $menu->route(), (*6)
Menu::create('test',function($menu){
// 'name rute' 'title' 'route parameters' 'attributes'
$menu->route('cars.show', 'Cars', ['name'=>'toyota'], ['icon'=>'icon-car']);
});
to create a dropdown menu item use $menu->dropdown(), (*7)
Menu::create('test',function($menu){
// 'title' 'attributes' 'callback '
$menu->dropdown('test',['icon'=>'icon-test'], function($item){
$item->link('/test','test1',['icon'=>'fa-fa-icon']);
$item->link('/test','test2',['icon'=>'fa-fa-icon']);
$item->link('/test','test3');
});
});
To create a drop-down menu within another drop-down menu use $item->dropdown(), (*8)
Menu::create('test',function($menu){
// 'title' 'attributes' 'callback '
$menu->dropdown('test',['icon'=>'icon-test'], function($item){
$item->link('/test','test1');
$item->dropdown('test',['icon'=>'icon-test'], function($item){
$item->link('/test','test2');
});
});
});
You can sort the menu items in two ways, by the order number or alphabetically., (*9)
By default in the configuration file the ordering is deactivated, you can activate it directly in the configuration file or use the method $menu->activeOrder()., (*10)
Menu::create('test',function($menu){
$menu->activeOrder();
});
To set the value of the order call the method ->order()., (*11)
Menu::create('test',function($menu){
$menu->activeOrder(); //active order
$menu->link('home/1','Home',['icon'=>'icon-home'])->order(1);
$menu->link('contact','Contact',['icon'=>'icon-contact'])->order(3);
$menu->link('pages','Pages',)->order(2);
});
To order alphabetically use the method $menu->setOrderBy($type)., (*12)
Menu::create('test',function($menu){
$menu->activeOrder();// active order
$menu->setOrderBy('title'); // 'title' or 'number'
});
By default, the orden function is disabled. You can enable the order function in your configuration file., (*13)
return [
'ordered' => true
];
And the type of order, by default is order by number., (*14)
return [
'orderBy' => 'title'
];
To render the menu you can use show or get method., (*15)
Menu::get('test');
Menu::show('test');
To edit a menu already created use the edit method of the facade Menu., (*16)
Menu::edit('test',function($menu){
$menu->link('home/1','Home',['icon'=>'icon-home']); // add link item
});
To edit an item in a menu., (*17)
Menu::edit('test',function($menu){
// 'search parameter' 'name'
$menuItem = $menu->edit('title', 'test');
$menuItem->title = 'hola';
});
To edit elements of a dropdown., (*18)
Menu::edit('test',function($menu){
// 'search parameter' 'name'
$menuItem = $menu->edit('title', 'test'); //dropdown item
$menuItem->link('/test2','testt2',['icon'=>'fa-fa-icon']); //add dropdown item
// 'search parameter' 'name'
$subMenuItem = $menuItem->edit('title', 'test1'); //edit dorpdown item
$subMenuItem->title = 'test3';
});
Configuration
to publish the package configuration use the following command, (*19)
``` bash
php artisan vendor:publish --provider="JMinayaT\Menus\MenusServiceProvider", (*20)
The content of the configuration file is as follows:
``` php
return [
'aspect' => [
'MtsysAdmin' => 'JMinayaT\Menus\Aspects\MtsysAdmin\SidebarMenuAspect',
],
'default_aspect' => 'MtsysAdmin',
'ordered' => false,
'orderBy' => 'number',
];
aspect
These are available ready to use menu aspects., (*21)
default_aspect
set the default aspect., (*22)
ordered
Enable or disable menu item ordering for all menus., (*23)
orderBy
Set the default order type in alphabet or number., (*24)
License
The MIT License (MIT). Please see License File for more information., (*25)