salahhusa9 / laravel-menu
Html menu generator for Laravel
Installs: 2 891
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 1
Forks: 1
Open Issues: 7
Requires
- php: ^8.1
- illuminate/contracts: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.0|^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- dev-main
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v0.0.1
- dev-renovate/shivammathur-setup-php-digest
- dev-renovate/major-phpstan-packages
- dev-v2-beta
- dev-renovate/pestphp-pest-3.x
- dev-renovate/pestphp-pest-plugin-laravel-3.x
- dev-renovate/pestphp-pest-plugin-arch-3.x
- dev-badgeName-as-callable
- dev-add-laravel-11-in-github-actions
- dev-support-laravel-11
- dev-problem-of-not-active-open-item-if-has-many-child-levels-and-one-active
- dev-Support-Multiple-Menu
- dev-check-Gate
This package is auto-updated.
Last update: 2024-11-18 16:15:46 UTC
README
This is a useful package for building menus in your Laravel application, and it can help simplify the process of creating and managing menus in your application.
Installation
You can install the package via composer:
composer require salahhusa9/laravel-menu
You can publish the config file with:
php artisan vendor:publish --tag="menu-config"
Optionally, you can publish the views using
php artisan vendor:publish --tag="menu-views"
Usage
Basic
You can create menu in your application in any place you want, but the best place is in the AppServiceProvider.php file in the boot() method.
use SalahHusa9\Menu\Facades\Menu; public function boot() { Menu::add('test', 'route.name', 'fa fa-home'); }
Add items to the menu using the add() method. You can chain multiple add() calls to add multiple items.
Menu::add('test') ->add('test2');
To create a submenu, call addSubmenu() on a menu item and add items to the submenu using the add() method.
Menu::add('test') ->add('test2') ->addSubmenu('test3', function ($submenu) { $submenu->add('test4'); }) ->add('test5');
Blade
To render the menu, use the <x-menu />
blade component.
<x-menu />
Customization of the menu
Icons can be added to the menu items by passing the icon parameter to the add() method.
Menu::add('test', 'route.name', ['icon' => 'fa fa-home']);
You can also add a id and class to the menu item by passing the id and class parameters to the add() method.
Menu::add('test', 'route.name',['class' => 'customClass', 'id' => 'customId']);
You can also add a target to the menu item by passing the target parameter to the add() method.
Menu::add('test', 'route.name', ['target' => '_blank']);
You can also add a badge to the menu item by passing the badgeClass and badgeName parameters to the add() method.
Menu::add('test', 'route.name', ['badgeClass' => 'badge badge-success', 'badgeName' => 'New']);
You can also
// old: if (auth()->user()->can('gateName')){ Menu::add('test', 'route.name'); } // new: Menu::add('test', 'route.name', ['gateName' => 'gateName']);
Customization of the menu view
You can customize the menu view by publishing the views using
php artisan vendor:publish --tag="menu-views"
Multiple Menus
You can create multiple menus in your application:
Menu::make('sidebar', function ($menu) { $menu->add('test', 'route.name'); }); Menu::make('main', function ($menu) { $menu->add('test', 'route.name'); });
For render the menu, use the <x-menu for="sidebar" />
blade component.
Configuration of the defult menu Classes of Ul and Li and the active class
You can publish the config file with:
php artisan vendor:publish --tag="menu-config"
and you can change the defult menu Classes of Ul and Li and the active class
return [ "ul_class" => "menu-inner py-1", // default menu class "ul_sub_menu_class" => "menu-sub", // default submenu class "li_class" => "menu-item", // default menu item class "li_sub_menu_class" => "menu-item", // default submenu item class "li_sub_menu_open_class" => "menu-item active open", // default submenu item class when open "a_class" => "menu-link", // default menu link class "a_sub_menu_class" => "menu-link menu-toggle", // default submenu link class "icon_class" => "menu-icon", // default menu icon class "li_active_class" => "active", // default active class of li "a_active_class" => "active", // default active class of a "badge_class" => "badge rounded-pill ms-auto", // default badge class ];
Advanced
Each Item accept this parames :
add( $name, $routeName = null, $options = [], ) addSubmenu( $name, callback $callbackOfSubmenu, $options )
There is other functions that you can used :
Menu::getMenuAsJson(); // return the menu as json Menu::renderAsJson(); // return the menu as json Menu::renderAsHtml(); // return the menu as html
Roadmap
See the open issues for a list of proposed features (and known issues).
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.