PHP code example of usamamuneerchaudhary / filament-command-palette
1. Go to this page and download the library: Download usamamuneerchaudhary/filament-command-palette library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
usamamuneerchaudhary / filament-command-palette example snippets
use Usamamuneerchaudhary\CommandPalette\FilamentCommandPalettePlugin;
public function panel(Panel $panel): Panel
{
return $panel->plugins([
FilamentCommandPalettePlugin::make(),
]);
}
FilamentCommandPalettePlugin::make()
->keyBindings(['mod+k'])
->template('groups')
->maxResults(12)
->recordSearch(true, maxResults: 20)
->recents(true, max: 5)
->pins(true, max: 8)
->topbarButton(false)
->cacheFor(60)
$panel
->globalSearchKeyBindings(['mod+shift+k'])
->plugins([
FilamentCommandPalettePlugin::make()->keyBindings(['mod+k']),
]);
use Usamamuneerchaudhary\CommandPalette\Support\CommandItem;
FilamentCommandPalettePlugin::make()
->commands(fn () => [
CommandItem::make('Billing portal', 'https://billing.example.com')
->group('External')
->openInNewTab()
->keywords(['invoice', 'subscription', 'payment']),
])
CommandItem::make('Clear application cache')
->icon(Heroicon::OutlinedTrash)
->action(function () {
Artisan::call('cache:clear');
Notification::make()->title('Cache cleared')->success()->send();
})
->authorize(fn () => auth()->user()->isAdmin())
CommandItem::make('Clear application cache')
->action(ClearApplicationCache::class)
class ClearApplicationCache
{
public function __invoke(CommandItem $command): void
{
Artisan::call('cache:clear');
}
}
use Usamamuneerchaudhary\CommandPalette\Contracts\HasPaletteCommands;
class EditInvoice extends EditRecord implements HasPaletteCommands
{
public static function getPaletteCommands(): iterable
{
return [
CommandItem::make('Regenerate PDF')
->action(fn (CommandItem $command, Invoice $record) => $record->regeneratePdf()),
];
}
}
CommandItem::make('Assign role')
->children([
CommandItem::make('Admin')->action(fn () => $this->assign('admin')),
CommandItem::make('Editor')->action(fn () => $this->assign('editor')),
])
use Usamamuneerchaudhary\CommandPalette\Contracts\HasPaletteRecordActions;
class UserResource extends Resource implements HasPaletteRecordActions
{
public static function getPaletteRecordActions(Model $record): iterable
{
return [
CommandItem::make('Impersonate')
->action(fn () => impersonate($record))
->authorize(fn () => auth()->user()->can('impersonate', $record)),
];
}
}
use Filament\Actions\Action;
CommandItem::make('Invite user')
->filamentAction(fn () => Action::make('invite')
->schema([
TextInput::make('email')->email()->
CommandItem::make('Create user')->mountAction('create')
CommandItem::make('Customers', CustomerResource::getUrl())->chord('g c')
CommandItem::make('Open help')->dispatch('open-help-drawer', ['section' => 'billing'])
CommandItem::make('Impersonate user', '/impersonate')
->visible(fn () => config('app.debug'))
->authorize(fn () => auth()->user()->can('impersonate'))
FilamentCommandPalettePlugin::make()
->authorize(fn (CommandItem $item) => ! str_starts_with($item->group, 'Internal'))
class OrderResource extends Resource
{
protected static ?string $recordTitleAttribute = 'reference';
public static function getGloballySearchableAttributes(): array
{
return ['reference', 'customer.name'];
}
public static function getGlobalSearchResultDetails(Model $record): array
{
return [
'Customer' => $record->customer->name,
'Total' => $record->total_formatted,
];
}
}
FilamentCommandPalettePlugin::make()->scoutIntegration()
use Usamamuneerchaudhary\CommandPalette\Contracts\CommandProvider;
class DocumentationCommands implements CommandProvider
{
public function commands(Panel $panel): iterable
{
return collect(Documentation::published())->map(
fn ($doc) => CommandItem::make($doc->title, $doc->url)->group('Docs')
);
}
}
FilamentCommandPalettePlugin::make()
->providers([...CommandRegistry::DEFAULT_PROVIDERS, DocumentationCommands::class])
use Usamamuneerchaudhary\CommandPalette\Events\CommandExecuted;
Event::listen(CommandExecuted::class, function (CommandExecuted $event) {
Log::info('palette', ['command' => $event->command['label'], 'query' => $event->query]);
});
FilamentCommandPalettePlugin::make()->cacheFor(300)
bash
php artisan command-palette:install
bash
php artisan vendor:publish --tag=command-palette-config
bash
php artisan vendor:publish --tag=command-palette-translations
bash
php artisan command-palette:publish-views