1. Go to this page and download the library: Download wire-elements/spotlight 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/ */
use LivewireUI\Spotlight\SpotlightCommand;
class Logout extends SpotlightCommand
{
protected string $name = 'Logout';
protected string $description = 'Logout out of your account';
}
use Illuminate\Contracts\Auth\StatefulGuard;
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
class Logout extends SpotlightCommand
{
protected string $name = 'Logout';
protected string $description = 'Logout out of your account';
public function execute(Spotlight $spotlight, StatefulGuard $guard): void
{
$guard->logout();
$spotlight->redirect('/');
}
}
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
class ViewBillingSettings extends SpotlightCommand
{
protected string $name = 'View Billing Settings';
protected string $description = 'Update your billing settings';
protected array $synonyms = [
'subscription',
'credit card',
'payment',
];
public function execute(Spotlight $spotlight): void
{
$spotlight->redirect('/settings/billing');
}
}
SpotlightCommandDependencies::collection()
->add(SpotlightCommandDependency::make('team')->setPlaceholder('For which team do you want to create a user?'))
->add(SpotlightCommandDependency::make('foobar')->setPlaceholder('Input from user')->setType(SpotlightCommandDependency::INPUT));
public function searchTeam($query)
{
return Team::where('name', 'like', "%$query%")
->get()
->map(function(Team $team) {
return new SpotlightSearchResult(
$team->id,
$team->name,
sprintf('Create license for %s', $team->name)
);
});
}
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
use LivewireUI\Spotlight\SpotlightCommandDependencies;
use LivewireUI\Spotlight\SpotlightCommandDependency;
use LivewireUI\Spotlight\SpotlightSearchResult;
class CreateUser extends SpotlightCommand
{
protected string $name = 'Create user';
protected string $description = 'Create new team user';
public function dependencies(): ?SpotlightCommandDependencies
{
return SpotlightCommandDependencies::collection()
->add(SpotlightCommandDependency::make('team')->setPlaceholder('For which team do you want to create a user?'))
->add(SpotlightCommandDependency::make('foobar')->setPlaceholder('Search for second dependency')
);
}
public function searchFoobar($query, Team $team)
{
// Given Foobar is the second dependency it will have access to any resolved depedencies defined earlier. In this case we can access the Team which was chosen.
}
public function searchTeam($query)
{
return Team::where('name', 'like', "%$query%")
->get()
->map(function(Team $team) {
return new SpotlightSearchResult(
$team->id,
$team->name,
sprintf('Create user for %s', $team->name)
);
});
}
public function execute(Spotlight $spotlight, Team $team, string $name)
{
$spotlight->emit('openModal', 'user-create', ['team' => $team->id, 'name' => $name]);
}
}
use \App\SpotlightCommands\CreateUser;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Spotlight::registerCommand(CreateUser::class);
// You can also register commands conditionally
Spotlight::registerCommandIf(true, CreateUser::class);
Spotlight::registerCommandUnless(false, CreateUser::class);
}
}
use Illuminate\Http\Request;
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
class CreateUser extends SpotlightCommand
{
protected string $name = 'Create user';
protected string $description = 'Create new team user';
public function execute(Spotlight $spotlight)
{
$spotlight->emit('openModal', 'user-create');
}
public function shouldBeShown(Request $request): bool
{
return $request->user()->can('create user');
}
}
use Illuminate\Http\Request;
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
class CreateUser extends SpotlightCommand
{
protected string $name = 'Create user';
protected string $description = 'Create new team user';
public function execute(Spotlight $spotlight)
{
$spotlight->emit('openModal', 'user-create');
}
public function shouldBeShown(Request $request): bool
{
return $request->user()->can('create user');
}
}
return [
/*
|--------------------------------------------------------------------------
| Shortcuts
|--------------------------------------------------------------------------
|
| Define which shortcuts will activate Spotlight CTRL / CMD + key
| The default is CTRL/CMD + K or CTRL/CMD + /
|
*/
'shortcuts' => [
'k',
'slash',
],
/*
|--------------------------------------------------------------------------
| Commands
|--------------------------------------------------------------------------
|
| Define which commands you want to make available in Spotlight.
| Alternatively, you can also register commands in your AppServiceProvider
| with the Spotlight::registerCommand(Logout::class); method.
|
*/
'commands' => [
\LivewireUI\Spotlight\Commands\Logout::class
],
/*
|--------------------------------------------------------------------------
| Include CSS
|--------------------------------------------------------------------------
|
| Spotlight uses TailwindCSS, if you don't use TailwindCSS you will need
| to set this parameter to true. This includes the modern-normalize css.
|
*/
'include_css' => false,
/*
|--------------------------------------------------------------------------
| Include JS
|--------------------------------------------------------------------------
|
| Spotlight will inject the
return [
'placeholder' => 'What do you want to do?',
];