Examples
Open Spotlight via JavaScript
You can open Spotlight from anywhere by sending the spotlight-open event.
html
<button onclick="window.dispatch('spotlight-open')">
Open Spotlight
</button>Directly go to ListPage
To go directly to the ListPage of a resource instead of displaying all records, extend the RegisterResources provider and override the registerResult() method.
php
use pxlrbt\FilamentSpotlightPro\SpotlightProviders\RegisterResources;
class CustomRegisterResources extends RegisterResources
{
protected function registerResult(string $resource): void
{
if ($this->useRootContext) {
return;
}
$context = getContextRoute($resource, parentSuffix: 'record');
Spotlight::register(
SpotlightResult::make()
->forContext($context)
->label($resource::getNavigationLabel())
->icon($resource::getNavigationIcon() ?? $this->getNavigationGroupIcon($resource::getNavigationGroup()))
->order($resource::getNavigationSort())
->closeOnSelect(false)
->url($resource::getUrl())
->group($this->getResourceGroup($resource))
->aliases(method_exists($resource, 'getSpotlightAliases') ? $resource::getSpotlightAliases() : null)
);
}
}Then register the new provider instead of the default one:
php
use pxlrbt\FilamentSpotlightPro\SpotlightPlugin;
$panel->plugin(
SpotlightPlugin::make()->register([
CustomRegisterResources::class
])
)Directly go to record
Instead of opening the record submenu, you might want to link to a page directly. Place this code on the resources where you want this behavior.
php
public static function modifySpotlightResult(SpotlightResult $result, $record): SpotlightResult
{
return $result
->action(null)
->url(static::getUrl('edit', $record));
}