usamamuneerchaudhary/filament-command-palette
composer require usamamuneerchaudhary/filament-command-palette
Panel provider:
use Usamamuneerchaudhary\CommandPalette\FilamentCommandPalettePlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FilamentCommandPalettePlugin::make(),
]);
}
Cmd+K (Mac) or Ctrl+K (Windows/Linux). The default palette includes navigation to resources, pages, and Filament’s built-in actions.Cmd+K).Add commands via the config file (config/command-palette.php):
'custom_commands' => [
fn () => [
\Usamamuneerchaudhary\CommandPalette\Support\CommandItem::make(
'Generate Report',
route('reports.generate'),
'Reports',
icon: 'heroicon-o-chart-bar',
),
\Usamamuneerchaudhary\CommandPalette\Support\CommandItem::make(
'Switch Tenant',
route('tenants.switch'),
'Tenants',
icon: 'heroicon-o-users',
),
],
],
Best Practice: Group commands by category (e.g., "Reports", "Tenants") for better UX.
Extend the plugin in a service provider to register commands dynamically:
use Usamamuneerchaudhary\CommandPalette\FilamentCommandPalettePlugin;
public function register()
{
FilamentCommandPalettePlugin::registerCustomCommands(
fn () => [
CommandItem::make(
'Create ' . $this->resource->modelLabel(),
$this->resource->getUrl('create'),
'Resources',
),
]
);
}
Add a custom action to a resource and expose it in the palette:
use Filament\Resources\Resource;
use Usamamuneerchaudhary\CommandPalette\Support\CommandItem;
public function getPages(): array
{
return [
// ... existing pages
];
}
public function registerCustomCommands(): void
{
FilamentCommandPalettePlugin::registerCustomCommands(
fn () => [
CommandItem::make(
'Bulk Delete',
$this->getUrl('bulk-delete'),
'Actions',
icon: 'heroicon-o-trash',
),
]
);
}
Use closures to show/hide commands based on auth, roles, or data:
'custom_commands' => [
fn () => [
auth()->user()->can('generate_reports')
? CommandItem::make(
'Generate Report',
route('reports.generate'),
'Reports',
)
: null,
],
],
Publish and customize the palette’s Blade views:
php artisan vendor:publish --tag=command-palette-views
Edit resources/views/vendor/command-palette/partials/palette.blade.php to modify:
Cmd+K conflicts with another tool (e.g., browser dev tools), override the shortcut in config/command-palette.php:
'key_bindings' => ['mod+shift+k'],
'show_topbar_button' => false,
'max_results' => 5, // Default is 10
CommandItem class to test command registration:
$command = CommandItem::make('Test', '/test', 'Test');
$this->assertEquals('Test', $command->label);
Filament Version Mismatch
v1.1 release.composer.json of the package for Filament version constraints.Command Duplication
CommandItem::make('Custom Publish', '/publish', 'Custom Actions'),
Keyboard Shortcut Overrides
Cmd+K (e.g., Safari’s "Find" feature).mod+shift+k or document the shortcut in your admin guide.View Publishing Issues
--force to overwrite:
php artisan vendor:publish --tag=command-palette-views --force
Permission-Based Commands
auth()->user()->can() checks.authorize() helper or Laravel’s gates:
FilamentCommandPalettePlugin::registerCustomCommands(
fn () => [
gate('view_reports') ? CommandItem::make(...) : null,
]
);
Log Command Registration Add debug logs to verify commands are registered:
\Log::debug('Custom commands:', [
FilamentCommandPalettePlugin::getCustomCommands(),
]);
Inspect Palette HTML
Use browser dev tools (Ctrl+Shift+I) to inspect the palette’s DOM structure when it renders. Look for:
!important conflicts).Check for JavaScript Errors
Open the browser console (F12) and filter for errors when opening the palette. Common issues:
route('reports.generate')).Disable Other Plugins If the palette fails to load, temporarily disable other Filament plugins to isolate conflicts:
->plugins([
// FilamentCommandPalettePlugin::make(), // Comment out others first
]),
Custom Command Categories Extend the palette to support nested categories (e.g., "Reports → Monthly"):
palette.blade.php) to add collapsible groups.<div x-data="{ open: false }">
<button @click="open = !open">Reports</button>
<div x-show="open">
<!-- Sub-commands -->
</div>
</div>
AI-Powered Suggestions Integrate with an API (e.g., OpenAI) to suggest commands based on user input:
'custom_commands' => [
fn () => [
CommandItem::make(
'AI Suggest: ' . request('query'),
route('ai.suggest', ['query' => request('query')]),
'AI',
),
],
],
Recent Commands Track and display frequently used commands using Laravel’s cache:
// In a service provider
FilamentCommandPalettePlugin::registerCustomCommands(
fn () => [
CommandItem::make(
'Recent: ' . cache()->get('last_command', 'None'),
'#',
'Recent',
),
]
);
Multi-Tenant Support Filter commands by tenant in a multi-tenant app:
'custom_commands' => [
fn () => [
tenant('company_id') === 1
? CommandItem::make('Company A Dashboard', route('tenants.dashboard'), 'Tenants')
: null
How can I help you explore Laravel packages today?