Closed vlados closed 3 years ago
You could do something like this:
class NavigateTo extends SpotlightCommand
{
protected string $name = 'Navigate to';
public function dependencies(): ?SpotlightCommandDependencies
{
return SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('page')
->setPlaceholder('To which page do you want to navigate?')
);
}
public function searchProduct(Request $request, $query)
{
return [
new SpotlightSearchResult(
'products',
'Products',
'Navigate to products'
),
new SpotlightSearchResult(
'users',
'Users',
'Navigate to users'
),
]
}
public function execute(Spotlight $spotlight, $page)
{
$spotlight->redirectRoute($page);
}
}
Yes. But this will add a command Navigate to and then search for page. I want the initial spotlight to have all this pages as commands
Not tested but this might work:
// AppServiceProvider
foreach(['products', 'users'] as $page) {
LivewireUI\Spotlight\Spotlight::$commands[] = new RedirectCommand($page);
}
class RedirectCommand extends SpotlightCommand
{
public function __construct($page)
{
$this->page = $page;
$this->name = "View {$page}";
}
public function execute(Spotlight $spotlight)
{
$spotlight->redirectTo($this->page);
}
}
If I want to bulk add multiple actions to the search and to have one class how to do it? For example: