Closed ndijkstra closed 2 years ago
You can now add synonyms to your search dependencies as well. For example:
<?php
namespace App\Spotlight;
use App\Models\User;
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
use LivewireUI\Spotlight\SpotlightCommandDependencies;
use LivewireUI\Spotlight\SpotlightCommandDependency;
use LivewireUI\Spotlight\SpotlightSearchResult;
class ViewLicensee extends SpotlightCommand
{
protected string $name = 'View user';
public function dependencies(): ?SpotlightCommandDependencies
{
return SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('user')
->setPlaceholder('Which user do you want to view?')
);
}
public function searchUser($query)
{
return User::query()
->where('name', 'like', "%$query%")
->orWhere('email', 'like', "%$query%")
->take(10)
->get()
->map(function(User $user) {
return new SpotlightSearchResult(
$licensee->id,
$licensee->name,
sprintf('View %s', $user->name),
[
$licensee->email
]
);
});
}
public function execute(Spotlight $spotlight, User $user)
{
//
}
}
Awesome! Thanks for your quick response and change
If I have in my dependency a filter to search on name or email, I don't see any results in the spotlight if I search on the email address. I do see that the result is returned in the debug bar.