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.
10 Replies
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.
You should just overwrite the table query via
modifyQuery()
instead of using getEloquentQuery()
This would then break the edit page and restore/delete functionality, wouldn't it?
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?i guess the resource stub could be updated so when we include the geteloquentquery modification, we also include getglobalsearcheloquentquery to apply the scope
I can create an issue on the repo if you'd like. I'd submit a PR but I'm not sure what you're thinking. It looks like the
->withGlobalScope()
signature is different and it's expecting an $identifier
.Yeah sure, please open an issue
GitHub
Global search query is pulling in trashed models · Issue #16123 ·...
Package filament/filament Package Version v3.3.4 Laravel Version v11.44.2 Livewire Version v3.6.2 PHP Version PHP 8.3.20 Problem description When following the documentation to add soft-deletes to ...
Soo @morty do you have the filter added with a default value? If you are doing that it's very possible the scope it being re-applied
Like a filter not related to the trashed filter?
In my actual application, yes I have things like this:
I added a reproduction repo though with the bare-minimum functionality to show the issue:
https://github.com/ryanmortier/filament-global-search-soft-delete-issue/blob/main/app/Filament/Resources/UserResource.php