F
Filament8mo ago
Damien

Is there a way to prevent soft deleted records appearing in global search?

I have checked the documentation for this but I cannot seem to find if this is a configurable option or not. I would like for records that have been soft deleted, to not be returned by the global search, is this possible?
7 Replies
MohamedSabil83
MohamedSabil838mo ago
The default behavior is not to display the soft deleted records when use SoftDeletes trait. But if it does for any reason, you can use getGlobalSearchEloquentQuery() method to modify the query
Damien
DamienOP8mo ago
Thank you Mohamed, I will take a look into that!
MohamedSabil83
MohamedSabil838mo ago
You're welcome
Damien
DamienOP8mo ago
Hey, I came back to this and tried adding the following to a resource class:
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
However I must be doing it in the wrong place / or something wrong as the soft-deleted records are still showing.
MohamedSabil83
MohamedSabil838mo ago
Hi! First, ensure that you are import the SoftDeletes trait in your model. If do and still soft-deleted records returned in the global search some how, then try to do the following as your code force it to display the soft delete records:
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery()->whereNull('deleted_at');
}
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery()->whereNull('deleted_at');
}
Damien
DamienOP8mo ago
Ok ill try this, is this on the project resource level? This appears to have worked thank you.
MohamedSabil83
MohamedSabil838mo ago
You're welcome
Want results from more Discord servers?
Add your server