Menu

A Cmd+K command palette for Laravel, built in PHP
📰

A Cmd+K command palette for Laravel, built in PHP

DEV Community: laravel·Amjad Iqbal·4 days ago
#eXmt71v6
#devtolaravel#devto#dev#ninja#keys
Long article (251 words) — no AI summary yet.
Reading 0:00
15s threshold

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() or href() 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' ) ; } ) ;

Enter fullscreen mode

Exit fullscreen mode

Permission-aware

can() runs your Gate abilities [1] on the server.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.