v0.0.2
Demos (demo panel, opens in a new tab)

JSON menu

Defines the application menu in a single JSON file; the vertical menu, the horizontal menu, the mobile drawer and the command palette search are drawn from that definition.

zb:menu zubazar/ui-pro

PRO

This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →

Basic usage

Basic usage: view
BLADE

Give the menu prop a file name, a full path, an array or a Menu object; the example uses an array, in an application use a JSON file.

blade
<nav class="flex flex-col gap-0.5">
    <zb:menu :menu="[
        ['section' => 'General'],
        ['title' => 'Orders', 'icon' => 'shopping-bag', 'url' => '#orders'],
        ['title' => 'Reports', 'icon' => 'chart-bar', 'children' => [
            ['title' => 'Sales report', 'url' => '#sales'],
            ['title' => 'Customer report', 'url' => '#customers'],
        ]],
    ]" />
</nav>
PropValues
menuFile name | full path | array | Menu object

JSON file

JSON

The file lives under resources/menu/; each item is a section heading (section) or a link or group with a title.

json
{
    "menu": [
        { "section": "General" },
        { "title": "Home", "icon": "home", "route": "home" },
        { "title": "Orders", "icon": "shopping-bag", "route": "orders.index", "active": "orders.*" },
        { "title": "Reports", "icon": "chart-bar", "badge": true, "children": [
            { "title": "Sales", "route": "reports.sales" },
            { "title": "Archive", "children": [
                { "title": "2025", "url": "/reports/archive/2025" }
            ] }
        ] },
        { "section": "Support" },
        { "title": "Help center", "icon": "lifebuoy", "url": "https://destek.ornek.com", "target": "_blank" }
    ]
}
PropValues
sectionSection heading; hidden when no items remain under it
titleDisplay name
iconzb:icon name

Badges and submenus

Badges and submenus: view
BLADE

badge puts a number or short text to the right of the item, and children builds submenus up to three levels deep.

blade
<nav class="flex flex-col gap-0.5">
    <zb:menu :menu="[
        ['title' => 'Notifications', 'icon' => 'bell', 'url' => '#', 'badge' => 6],
        ['title' => 'Imports', 'icon' => 'arrow-up-tray', 'url' => '#imports', 'badge' => 'New'],
        ['title' => 'Reports', 'icon' => 'chart-bar', 'badge' => true, 'children' => [
            ['title' => 'Sales', 'url' => '#sales'],
            ['title' => 'Customers', 'url' => '#customers'],
            ['title' => 'Archive', 'children' => [
                ['title' => '2025', 'url' => '#2025'],
                ['title' => '2024', 'url' => '#2024'],
            ]],
        ]],
    ]" />
</nav>
PropValues
badgeNumber | text | true (number of child items)
childrenChild items; up to 3 levels

Using it in a layout

BLADE

Put the menu in the layout's nav slot; horizontal draws a horizontal top menu, and searchItems() gives the same links to the command palette.

blade
{{-- Vertical layout: menu and search from the same file --}}
<zb:layout.sidebar>
    <zb:slot:nav><zb:menu menu="sidebar" /></zb:slot:nav>
    <zb:slot:search>
        <zb:command-palette :items="\Zubazar\Panel\Menu::fromFile('sidebar')->searchItems()" />
    </zb:slot:search>
    …
</zb:layout.sidebar>

{{-- Horizontal layout: horizontal menu on top, vertical menu in the mobile drawer --}}
<zb:layout.horizontal>
    <zb:slot:nav><zb:menu menu="sidebar" horizontal /></zb:slot:nav>
    <zb:slot:mobileNav><zb:menu menu="sidebar" /></zb:slot:mobileNav>
    …
</zb:layout.horizontal>
PropValues
horizontaltrue | false

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
menu— — Required; a file name (resources/menu/…json), a full path, an array or a Menu object
horizontalbooleanfalseHorizontal (top) menu; section headings are not shown
sections—autoIn the horizontal menu, true turns each section into a single dropdown (its groups open to the side); false lays the items out side by side; auto uses sections when there are more than 6 items
section— — JSON: section heading; top level only
title— — JSON: display name
icon—nullJSON: zb:icon name; shown on the top level
route—nullJSON: route name; if it is not defined, the link is #
params—[]JSON: route parameters
url—nullJSON: a relative path or an http, https, mailto or tel address; anything else becomes # (//host only with the application's own host)
active—nullJSON: a route name or a /path pattern (can be an array, * is a wildcard)
badge—nullJSON: a number or text; on a group, true = number of child items
target—nullJSON: _blank = new tab, wire:navigate is not used
children— — JSON: child items; up to 3 levels

Advanced

2 examples

Active page

JSON

Without active, a route item is active while that route is open and a url item when the address matches exactly. To keep an item active on subpages too, give active route names or path patterns starting with / (* is a wildcard).

json
{
    "menu": [
        { "title": "Orders", "icon": "shopping-bag", "route": "orders.index", "active": "orders.*" },
        { "title": "Reports", "icon": "chart-bar", "url": "/reports", "active": ["/reports", "/reports/*"] }
    ]
}
PropValues
activeRoute name | /path pattern | an array of these

Building it in PHP

PHP

Build the menu in PHP with the Zubazar\Panel\Menu class, for example from an array that comes from a database. transform changes every item before it is rendered; isActive decides whether an item is active, and when it returns null the default rule applies.

php
use Zubazar\Panel\Menu;

$menu = new Menu(
    $definition,
    // Every item passes through here before it is rendered: turn your own field into a link.
    transform: fn (array $item) => isset($item['module'])
        ? ['url' => '/modules/'.$item['module']] + $item
        : $item,
    // true / false: whether the item is active; null: leave it to the default rule.
    isActive: fn (array $item) => isset($item['module']) ? $item['module'] === $activeModule : null,
);

// Blade: <zb:menu :menu="$menu" />
// Command palette: $menu->searchItems()
PropValues
transformfn (array $item): array
isActivefn (array $item): ?bool

Developer notes

Events, hooks and details
  • The layouts' nav slot already wraps the menu; when you use it on its own, put it inside a <nav>.
  • The menu does no authorization checks; the application decides which items are shown.
  • Because menu data can also come from a database, only http, https, mailto and tel addresses and relative paths are accepted; anything else (e.g. javascript:) becomes #.
  • A scheme-less //host/path address is kept only when it points to the application's own host; otherwise it becomes #.
  • External addresses are never considered active; a group that contains the active item is rendered open.
  • The children field of third-level items is ignored; badges are shown at every level in both the vertical and the horizontal menu.
  • In the horizontal menu, section headings are skipped and groups become dropdown panels; for the mobile drawer, pass the same file to the mobileNav slot as a vertical menu.
  • The old class name Zubazar\Ui\Menu\Menu keeps working until 3.0.
Zubazar UI · ZubazarDesigned for people.