Skip to main content

Menus

The Menus system allows you to fully customize, extend, or override the different menus available in the admin panel. This system supports registering new menus, unregistering items, and hooking into existing ones via service providers.

Available Admin Menu Types

There are three core types of admin menus:

  1. Admin Sidebar Menu (admin_main_menu) The main sidebar displayed on all admin pages.

  2. Admin User Menu (admin_user_menu) The dropdown menu located on the top-right corner, associated with the authenticated admin user.

  3. Admin Quick Navigation Menu (admin_quick_navigation_menu) A compact menu for quick links and shortcuts.

Registering Menus

Menus are registered using the Menu facade (bound to MenuManager) typically inside your Service Provider’s boot method.

use Qoraiche\Peak\Facades\Menu;

public function boot()
{
Menu::register('admin', [
[
'title' => 'Dashboard',
'route' => 'admin.dashboard',
'icon' => 'heroicon-o-home',
'order' => 1,
],
]);
}

Menu Item Structure

[
'title' => 'Item Title',
'route' => 'route.name',
'icon' => 'heroicon-o-something',
'order' => 1,
'slug' => 'optional-custom-slug', // auto-generated if not provided
'children' => [...], // nested items
'roles' => ['admin'],
'permissions' => ['edit-posts'],
]

Adding a Child Menu Item

To add a child item under an existing parent:

Menu::addChildToMenu('admin', 'dashboard', [
'title' => 'Sub Item',
'route' => 'admin.subitem',
'order' => 2,
]);

Unregistering Menu Items

You can remove a menu item by its slug:

Menu::unregister('admin', 'settings');

Hooks

Hooks let you modify menus before or after registration and fetching:

Menu::addHook('before_register', 'admin', function ($slug, $items) {
// Modify the $items array before it's saved
return $items;
});

Menu::addHook('after_fetch', 'admin', function ($slug, $items) {
// Append a dynamic item
$items[] = [
'title' => 'Realtime Logs',
'route' => 'admin.logs',
'icon' => 'heroicon-o-terminal',
'order' => 50,
];
return $items;
});

Available hook types:

  • before_register
  • after_register
  • before_fetch
  • after_fetch

Each menu goes through the following stages:

  1. Hooked: Items can be modified via before_register & after_register hooks.
  2. Registered: Items are stored with unique slugs.
  3. Fetched: Items are filtered:
  • By current user's roles and permissions
  • Marked as active based on the current route
  • Sorted by the order key
  • Hooked via before_fetch and after_fetch