---
title: Commands
published: 2026-11-04
lastmod: 2026-11-04
url: https://larasell.dev/docs/admin/guides/commands
---

## Table of contents
- [Registering commands](#registering-commands)
- [Icons](#icons)
- [Nested commands](#nested-commands)
- [Commands that depend on the page](#commands-that-depend-on-the-page)
  - [Disabling commands](#disabling-commands)
- [Commands for a single page](#commands-for-a-single-page)

# Commands

The admin panel has a command menu that opens with `⌘K` on macOS and `Ctrl+K`
everywhere else. It lists commands, like switching the theme, that
admins can search and run from the keyboard. You can add your own commands to it.

## Registering commands

Register commands in a `Larasell.booting()` callback. For an app, that's
`resources/js/admin/app.tsx`, which the panel loads on every admin page. For an extension, it's
the script the extension registers with `AdminPanel::vite()`.

Each command needs a unique `id`, a `label`, and a `run` function that runs when the admin picks it:

```ts
import { router } from '@inertiajs/react';
import { Larasell } from '@larasell-dev/admin';

Larasell.booting(({ commands }) => {
    commands.register({
        id: 'orders.archived',
        label: 'Show archived orders',
        keywords: ['history', 'old'],
        run: () => router.visit('/admin/orders?archived=1'),
    });
});
```

Commands registered this way appear on every page. The menu lists the panel's own commands
first, then yours in the order you registered them. The menu closes after a command runs.

Search matches a command's `label` and its `keywords`, so add words admins might type that aren't
in the label.

Ids must be unique, and registering an id twice throws an error. In an extension, prefix each id
with the extension's name, such as `larasell-reviews.publish-all`, so it can't clash with another
extension.

## Icons

Show an icon before the label with `icon`. It takes a [Remix icon](https://remixicon.com) from
`@larasell-dev/ui/icons`:

```ts
import { ArchiveLine } from '@larasell-dev/ui/icons';

commands.register({
    id: 'orders.archived',
    label: 'Show archived orders',
    icon: ArchiveLine,
    run: () => router.visit('/admin/orders?archived=1'),
});
```

Icons are bundled with your own code, so install `@larasell-dev/ui` in your app or extension to
import them. Labels of commands without an icon still line up with the others.

## Nested commands

A command with `items` instead of `run` opens a nested list when the admin picks it. Each item has
its own `id`, `label` and `run`. Set `checked` on the item that is currently in use, and the menu
marks it with a check:

```ts
commands.register({
    id: 'acme.density',
    label: 'Change table density',
    placeholder: 'Search densities',
    items: [
        { id: 'compact', label: 'Compact', run: () => setDensity('compact') },
        {
            id: 'comfortable',
            label: 'Comfortable',
            checked: true,
            run: () => setDensity('comfortable'),
        },
    ],
});
```

`placeholder` replaces the text in the search field while the nested list is open.

Searching from the top level also finds nested items. Typing "compact" shows
**Change table density › Compact**, which runs straight away when picked.

Pressing `Esc` clears the search, then goes back to the top level, then closes the menu.

## Commands that depend on the page

Give a command a `use` hook instead of fixed fields when it depends on the current page or other
state. The menu calls the hook while it's open, so the hook can use React and Inertia hooks. It
returns the command's fields, or `null` to hide the command:

```ts
import { router, usePage } from '@inertiajs/react';
import { defineCommand, Larasell } from '@larasell-dev/admin';

const exportOrders = defineCommand({
    id: 'acme.export-orders',
    use() {
        const { url } = usePage();

        if (!url.startsWith('/admin/orders')) {
            return null;
        }

        return {
            label: 'Export orders',
            run: () => router.post('/admin/orders/export'),
        };
    },
});

Larasell.booting(({ commands }) => commands.register(exportOrders));
```

`defineCommand` adds types to a command you define in its own module. It returns the command
unchanged.

### Disabling commands

Set `disabled` to explain why a command can't run right now. The menu shows the reason in place of
the command's check mark and won't run the command, open its nested list, or find its items:

```ts
return {
    label: 'Export orders',
    disabled: orders.length === 0 && 'No orders to export',
    run: () => router.post('/admin/orders/export'),
};
```

## Commands for a single page

To offer a command only on one page, call `useCommand` in that page's component. It takes the same
fields as `commands.register()`. The command is in the menu while the component is mounted and
goes away when the admin leaves the page:

```ts
import { router } from '@inertiajs/react';
import { SidebarLayout, useCommand } from '@larasell-dev/admin';

export default function Report({ downloadUrl }: { downloadUrl: string }) {
    useCommand({
        id: 'acme.report.download',
        label: 'Download report',
        run: () => router.visit(downloadUrl),
    });

    return <SidebarLayout>{/* … */}</SidebarLayout>;
}
```

The menu lists page commands after the global ones. A page command always uses the latest props
of its component, so you don't need to pass dependencies.
