Downloads
Stars
Version
jminayat/modules-laravel
is a package for the administration of menus in laravel. compatible with Laravel version 5.5.
Install the package through the composer.
composer require jminayat/laravel-menu
Next, publish the package configuration file by running:
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.
Menu::create('test',function($menu){
$menu->link('home/1','Home',['icon'=>'icon-home']);
});
If you want to create multiple menus
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()
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()
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()
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()
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.
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()
.
Menu::create('test',function($menu){
$menu->activeOrder();
});
To set the value of the order call the method ->order()
.
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)
.
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.
return [
'ordered' => true
];
And the type of order, by default is order by number.
return [
'orderBy' => 'title'
];
To render the menu you can use show
or get
method.
Menu::get('test');
Menu::show('test');
To edit a menu already created use the edit
method of the facade Menu.
Menu::edit('test',function($menu){
$menu->link('home/1','Home',['icon'=>'icon-home']); // add link item
});
To edit an item in a menu.
Menu::edit('test',function($menu){
// 'search parameter' 'name'
$menuItem = $menu->edit('title', 'test');
$menuItem->title = 'hola';
});
To edit elements of a dropdown.
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';
});
to publish the package configuration use the following command
php artisan vendor:publish --provider="JMinayaT\Menus\MenusServiceProvider"
The content of the configuration file is as follows:
return [
'aspect' => [
'MtsysAdmin' => 'JMinayaT\Menus\Aspects\MtsysAdmin\SidebarMenuAspect',
],
'default_aspect' => 'MtsysAdmin',
'ordered' => false,
'orderBy' => 'number',
];
These are available ready to use menu aspects.
set the default aspect.
Enable or disable menu item ordering for all menus.
Set the default order type in alphabet or number.
The MIT License (MIT). Please see License File for more information.