A Cmd+K command palette for Laravel, built in PHP
Laravel Ninja Keys adds a keyboard-first Cmd+K / Ctrl+K command palette to a Laravel app. You define the actions in PHP and render the ninja-keys web component [2] with one Blade tag. It works with Blade, Livewire and Al
Laravel Ninja Keys adds a keyboard-first Cmd+K / Ctrl+K command palette to a Laravel app. You define the actions in PHP and render the ninja-keys web component [2] with one Blade tag. It works with Blade, Livewire and Alpine.
The problem
Using ninja-keys by hand means a script in every layout, an action list built in JavaScript, and remembering which actions each user may see. The package handles those parts.
How it works
- Register actions with a fluent builder, using
route()orhref()so navigation needs no JavaScript. - Render the palette with
before. -
define()callbacks run at render time, so they can use the logged-in user and current route.
NinjaKeys::define(function (Manager $palette) {
$palette->addAction('users')->title('Manage users')
->route('users.index')->can('manage-users');
});
Permission-aware
can() runs your Gate abilities [1] on the server. Hidden actions and their sub-actions are removed, so they never appear in the page source.
Safety and limits
- ninja-keys 1.2.2 is bundled and self-hosted; no third-party script requests unless you choose the CDN.
- Survives Livewire
wire:navigate[3] without duplicate shortcuts. - ninja-keys' last release is 1.2.2 (July 2022); the package works around three bugs.
Install
composer require amjadiqbal/laravel-ninja-keys
MIT licensed. Requires PHP 8.3+ and Laravel 12 or 13. Docs and demo: https://urlshortly.com/UlcqQ. Source: https://urlshortly.com/etAOf.
References
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.