wire-elements/spotlight
Wire Elements Spotlight adds a Spotlight/Alfred-style command palette to Laravel via Livewire. Open with Ctrl/Cmd+K (or customize), search and run actions, and toggle from Livewire or JavaScript. Works with Alpine when using Livewire v2.
Installation
composer require wire-elements/spotlight
Add the Livewire directive to your layout (e.g., resources/views/layouts/app.blade.php):
@livewire('livewire-ui-spotlight')
For Livewire v2, include Alpine.js:
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
Trigger Spotlight
Use keyboard shortcuts (CTRL/CMD + K or CTRL/CMD + /) or dispatch via Livewire/Alpine:
// Livewire v3
$this->dispatch('toggle-spotlight');
<!-- Alpine -->
<button @click="$dispatch('toggle-spotlight')">Open Spotlight</button>
Create a Basic Command Generate a command:
php artisan make:spotlight Logout
Edit the generated file (app/SpotlightCommands/Logout.php):
class Logout extends SpotlightCommand {
protected string $name = 'Logout';
protected string $description = 'Logout of your account';
public function execute(Spotlight $spotlight) {
Auth::logout();
$spotlight->redirect('/');
}
}
Register the Command
Add the command to config/livewire-ui-spotlight.php:
'commands' => [
\App\SpotlightCommands\Logout::class,
],
Command Organization
Group related commands in a dedicated namespace (e.g., App\SpotlightCommands\Admin) and register them in bulk:
// AppServiceProvider
public function boot() {
Spotlight::registerCommand(\App\SpotlightCommands\Admin\CreateUser::class);
Spotlight::registerCommand(\App\SpotlightCommands\Admin\DeleteUser::class);
}
Dependency Handling Use dependencies for multi-step actions (e.g., user creation with team selection):
public function dependencies() {
return SpotlightCommandDependencies::collection()
->add(SpotlightCommandDependency::make('team')->setPlaceholder('Select a team'));
}
public function searchTeam($query) {
return Team::where('name', 'like', "%$query%")
->get()
->map(fn(Team $team) => new SpotlightSearchResult($team->id, $team->name, 'Team: ' . $team->name));
}
Conditional Commands Hide/show commands based on user roles or permissions:
public function shouldBeShown(Request $request) {
return $request->user()->hasRole('admin');
}
Dynamic UI Actions Emit Livewire events or open modals:
public function execute(Spotlight $spotlight, Team $team) {
$spotlight->emit('openModal', 'create-user', ['team_id' => $team->id]);
}
Search Synonyms Expand discoverability with synonyms:
protected array $synonyms = ['billing', 'payments', 'invoice'];
$spotlight->emit() to trigger actions in other Livewire components.SpotlightCommand dependencies in unit tests:
$this->partialMock(Spotlight::class, function ($mock) {
$mock->shouldReceive('redirect')->with('/dashboard');
});
Shortcut Conflicts
CTRL/CMD + K/ /) may conflict with browser extensions or other apps.config/livewire-ui-spotlight.php:
'shortcuts' => ['shift', 's'], // CTRL/CMD + Shift + S
Alpine.js Missing (Livewire v2)
Command Registration Overrides
config/livewire-ui-spotlight.php override those in AppServiceProvider.Spotlight::registerCommandUnless() for conditional overrides.Dependency Resolution Failures
searchTeam method) will crash Spotlight.shouldBeShown() or use try-catch in execute().Livewire v2 vs. v3 Dispatch
dispatchBrowserEvent (v2) and dispatch (v3) will fail.dispatch for v3 and wrap in if (method_exists($this, 'dispatch')) for backward compatibility.execute() or shouldBeShown():
\Log::debug('Executing command', ['command' => $this->name]);
php artisan vendor:publish --tag=livewire-ui-spotlight-views
fuse.js is loaded (check include_js config).Custom Views Override the default Spotlight template by publishing and modifying:
php artisan vendor:publish --tag=livewire-ui-spotlight-views
Key files: resources/views/vendor/livewire-ui-spotlight/spotlight.blade.php.
Dynamic Command Loading
Load commands dynamically (e.g., from a database) by implementing a SpotlightCommandProvider interface.
Custom Styling
Disable Tailwind CSS inclusion ('include_css' => false) and add your own CSS:
<link rel="stylesheet" href="{{ asset('css/spotlight-custom.css') }}">
Localization Extend translations by publishing the language file:
php artisan vendor:publish --tag=livewire-ui-spotlight-translations
Add custom keys to resources/lang/en/spotlight.php.
Performance
boot() to avoid eager loading.@debounce to optimize search queries:
<input @input.debounce.300ms="$wire.call('search', $event.target.value)">
How can I help you explore Laravel packages today?