How to disable global search for resource?

Hi guys, this is my UserResource. I am trying to disable global search just for this resource. What am I doing wrong?
No description
8 Replies
LeandroFerreira
Please share the code, not an image
Trauma Zombie
Trauma ZombieOP3w ago
class UserResource extends Resource
{
protected static ?string $model = User::class;

protected static ?string $navigationIcon = 'heroicon-o-users';

protected static ?int $navigationSort = 1;

public static function getRecordTitleAttribute(): ?string
{
return null;
}

public static function getModelLabel(): string
{
return 'Používateľ';
}

public static function getPluralModelLabel(): string
{
return 'Používatelia';
}

public static function getNavigationLabel(): string
{
return 'Používatelia';
}

public static function getNavigationGroup(): ?string
{
return 'Administrácia';
}

public static function getNavigationParentItem(): ?string
{
return null;
}

public static function getNavigationBadge(): ?string
{
return null;
}

public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'view' => Pages\ViewUser::route('/{record}'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}

/** @return Builder<User> */
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery();
}

/** @param User $record */
public static function getGlobalSearchResultTitle(Model $record): string
{
return $record->name;
}

public static function getGloballySearchableAttributes(): array
{
return ['name', 'email'];
}

/** @param User $record */
public static function getGlobalSearchResultDetails(Model $record): array
{
return [
'Email' => $record->email,
];
}

/** @return Builder<User> */
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery();
}
}
class UserResource extends Resource
{
protected static ?string $model = User::class;

protected static ?string $navigationIcon = 'heroicon-o-users';

protected static ?int $navigationSort = 1;

public static function getRecordTitleAttribute(): ?string
{
return null;
}

public static function getModelLabel(): string
{
return 'Používateľ';
}

public static function getPluralModelLabel(): string
{
return 'Používatelia';
}

public static function getNavigationLabel(): string
{
return 'Používatelia';
}

public static function getNavigationGroup(): ?string
{
return 'Administrácia';
}

public static function getNavigationParentItem(): ?string
{
return null;
}

public static function getNavigationBadge(): ?string
{
return null;
}

public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'view' => Pages\ViewUser::route('/{record}'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}

/** @return Builder<User> */
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery();
}

/** @param User $record */
public static function getGlobalSearchResultTitle(Model $record): string
{
return $record->name;
}

public static function getGloballySearchableAttributes(): array
{
return ['name', 'email'];
}

/** @param User $record */
public static function getGlobalSearchResultDetails(Model $record): array
{
return [
'Email' => $record->email,
];
}

/** @return Builder<User> */
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery();
}
}
Yeah, sorry, it was too long. I deleted form method.
LeandroFerreira
public static function getRecordTitleAttribute(): ?string
{
return null;
}
public static function getRecordTitleAttribute(): ?string
{
return null;
}
it should disable global search
Trauma Zombie
Trauma ZombieOP3w ago
I was thinking that, but I can still search for users. Maybe something I defined at bottom of my snippet?
Trauma Zombie
Trauma ZombieOP3w ago
I tried php artisan filament:optimize-clear, but still got results from global search. Oh, I figured out. I had defined getGloballySearchableAttributes.
LeandroFerreira
ahh I think getGlobalSearchResultTitle and getGloballySearchableAttributes will also apply the global search
Trauma Zombie
Trauma ZombieOP3w ago
Yeah, I just need to pass empty array to searchable attributes and it will disable global search. Thank you Leandro. 🙂
Want results from more Discord servers?
Add your server