Register Resources
Use the RegisterResources
provider to automatically register all your resources.
use pxlrbt\FilamentSpotlightPro\SpotlightPlugin;
use pxlrbt\FilamentSpotlightPro\SpotlightProviders\RegisterResources;
$panel->plugins([
SpotlightPlugin::make()->registerItems([
RegisterResources::make()
])
])
Excluding Resources
You can exclude resources by passing an array of resource classes to the ->except()
. method.
SpotlightPlugin::make()->registerItems([
RegisterResources::make()->except([
UserResource::class
])
])
You can also exclude resources by adding the static shouldRegisterSpotlight()
method to your resource class and return false
.
class UserResource extends Resource
{
public static function shouldRegisterSpotlight(): bool
{
return false;
}
}
Authorization
Spotlight uses canAccess()
and canViewAny()
methods on your Resource classes to determine if a user can view or access a resource.
Default SpotlightResult
The RegisterResources
provider will automatically generate a SpotlightQuery
for every resource class that the current panel is aware of.
The SpotlightQuery
will use the "Global Search" methods for the default SpotlightResult
like getGlobalSearchEloquentQuery()
, getGloballySearchableAttributes()
and getGlobalSearchResultTitle()
. If there is not dedicated global search method it will fallback to the navigation methods.
Custom SpotlightResult
Instead of the auto generated SpotlightResult
you can also create your own by adding the toSpotlightResult()
method to your Resource class.
class UserResource extends Resource
{
public function toSpotlightResult(): SpotlightResult
{
return SpotlightResult::make()
->title('Users')
->description('Your users')
->icon('heroicon-o-user-group')
}
}
You can also just modify the auto generated SpotlightResult
by adding the modifySpotlightResult()
method to your Resource class.
class UserResource extends Resource
{
public function modifySpotlightResult(SpotlightResult $result, Model $record): SpotlightResult
{
return $result->icon('heroicon-o-user-group');
}
}
Custom Resource Commands
By default Spotlight tries to register commands to go to ViewRecord
and EditRecord
page. If your resource uses actions it tries to register a simple version of those actions which contain an Infolist
or Form
. It also adds a simple DeleteAction
.
You can override the commands for a resource by defining the static getSpotlightCommands()
method.
class UserResource extends Resource
{
public static function getSpotlightCommands(Model $record): array
{
// Only register view action
return collect([
SpotlightResult::make('View')
->icon('heroicon-o-eye')
->infolist([
TextEntry::make('Name', $record->name),
]),
]);
}
}
Instead of completely overriding the commands you can also modify the auto generated commands by adding the modifySpotlightCommands()
method to your Resource class.
class UserResource extends Resource
{
public static function modifySpotlightCommands(Collection $commands, Model $record): array
{
// Remove delete command
$commands->pull('delete');
return $commands;
}
}