az-iar / menu
Menu builder
Installs: 5 717
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0 | ^8.1 | ^8.2
Requires (Dev)
- orchestra/canvas: ^8.1
- orchestra/testbench: ^v8.5
README
Simple menu builder for Laravel
Installation
Run this to install:
composer require az-iar/menu
How To Use
You can generate menu item using php artisan make:menu Dashboard
. It will create a menu item like this
namespace App\Menus; class Dashboard { use AsMenuItem; public function href(): string { // TODO: Implement href() method. } public function title(): string { // TODO: Implement title() method. } // Override default method from `AsMenuItem` trait public function authorize(): bool { return auth()->check() && auth()->user()->can('view-dashboard'); } ... }
Then create menu in AppServiceProvider
inside boot
method
use Inneuron\NavMenu\Facades\Menu; use Inneuron\Menu\Concerns\AsMenuItem; // Add menu item // Default menu $menu = Menu::create() ->addItem(new Dashboard) ->addItem(new Users) ->addItem(new Settings); // Another menu $menu = Menu::create('profile') ->addItem(new MyProfile) ->addItem(new Notifications) ->addItem(new Settings);
Use it like this
use Inneuron\NavMenu\Facades\Menu; // Output as array Menu::get(); Menu::get('profile'); // Render in HTML Menu::render(); Menu::render('profile');