F
Filament21h ago
morty

Global search query is pulling in trashed models

My global search queries don't seem to be applying the soft delete scope. Is this intentional? For example, here is one of the queries. The Part model has the soft delete trait.
select top 50 * from [maintenance].[parts] where ([maintenance].[parts].[name] like '%#40%' or [maintenance].[parts].[number] like '%#40%')
select top 50 * from [maintenance].[parts] where ([maintenance].[parts].[name] like '%#40%' or [maintenance].[parts].[number] like '%#40%')
5 Replies
morty
mortyOP20h ago
After looking at the source, it seems the global search query is just using the regular query which when using soft deletes you have to remove the soft delete scope. I've added withoutTrashed() to all of my resources that are global search enabled. It seems like this shouldn't be the default though imo.
public static function getGlobalSearchEloquentQuery(): Builder
{
return static::getEloquentQuery();
}
public static function getGlobalSearchEloquentQuery(): Builder
{
return static::getEloquentQuery();
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScope(SoftDeletingScope::class);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScope(SoftDeletingScope::class);
}
Dennis Koch
Dennis Koch20h ago
You should just overwrite the table query via modifyQuery() instead of using getEloquentQuery()
morty
mortyOP20h ago
This would then break the edit page and restore/delete functionality, wouldn't it?
Dennis Koch
Dennis Koch20h ago
Oh yes. You are right. Then you probably need to adjust readd the scope via the getGlobalSearchEloquentQuery. @Dan Harrin Maybe we should add a note to the docs? Or is there another way around this?
Dan Harrin
Dan Harrin19h ago
i guess the resource stub could be updated so when we include the geteloquentquery modification, we also include getglobalsearcheloquentquery to apply the scope

Did you find this page helpful?