- Installation
- Demo
- Create Menu
- Create Menu Item
- Create multiple Menu Items
- Menu Tree
- Menu Link Tokens
- Install the package via composer
composer require balajidharma/laravel-menu
- Publish the migration and the config/menu.php config file with
php artisan vendor:publish --provider="BalajiDharma\LaravelMenu\MenuServiceProvider"
- Run the migrations
php artisan migrate
The "Basic Laravel Admin Penel" starter kit come with Laravel Menu
use BalajiDharma\LaravelMenu\Models\Menu;
Menu::create([
'name' => 'Main Menu',
'machine_name' => 'main_menu',
'description' => 'Site main menu',
]);
use BalajiDharma\LaravelMenu\Models\Menu;
use BalajiDharma\LaravelMenu\Models\MenuItem;
$menu = Menu::create([
'name' => 'Main Menu',
'machine_name' => 'main_menu',
'description' => 'Site main menu'
]);
$menu->menuItems()->create([
'name' => 'Home',
'uri' => '/',
'enabled' => 1,
'parent_id' => null,
'weight' => 0
]);
$menu = Menu::create([
'name' => 'Admin',
'machine_name' => 'admin',
'description' => 'Admin Menu',
]);
$menu_items = [
[
'name' => 'Dashboard',
'uri' => '/dashboard',
'enabled' => 1,
'weight' => 0,
],
[
'name' => 'Permissions',
'uri' => '/<admin>/permission',
'enabled' => 1,
'weight' => 1,
],
[
'name' => 'Roles',
'uri' => '/<admin>/role',
'enabled' => 1,
'weight' => 2,
],
[
'name' => 'Users',
'uri' => '/<admin>/user',
'enabled' => 1,
'weight' => 3,
],
[
'name' => 'Menus',
'uri' => '/<admin>/menu',
'enabled' => 1,
'weight' => 4,
]
];
$menu->menuItems()->createMany($menu_items);
- Get menu tree by using menu id
use BalajiDharma\LaravelMenu\Models\MenuItem;
$items = (new MenuItem)->toTree($menu->id);
- Get menu tree by using menu machine name
use BalajiDharma\LaravelMenu\Models\Menu;
$items = Menu::getMenuTree('admin');
- Enter
<admin>
to add admin prefix to the link. - Enter
<nolink>
for non link menu.
Get the generated uri on link
attribute
use BalajiDharma\LaravelMenu\Models\MenuItem;
MenuItem::find(1)->link;