OrWhere creates AND in Filter

I am experiencing a very strange behavior when creating an OR-query on a Filter. I have a DocumentResource - by default I only want to show the documents with the status "draft" and "final". With the Filter I also want to show the documents with status "archive". So i provided this which returns the following query. parent::getEloquentQuery()->visible(); // select count() as aggregate from documents where status in ('draft', 'final') So far so good. In the Filter i provided this: ->query(fn (Builder $query): Builder => $query->orWhere->archived() which strangely does not create an OR condition as expected but instead creates this AND condition: select count() as aggregate from documents where status in ('draft', 'final') and ((status = 'archive')) I tried all the variations of orWhere() and also used the scopes in a normal Controller Action and it worked totally as expected. So what is happening here, when providing the
3 Replies
whatsisname
whatsisnameOP16mo ago
I did not finish my sentence, but I was basically finished 🙂 So what is happening here? 🧐
Kenneth Sese
Kenneth Sese15mo ago
@whatsisname By default Filament wraps all queries in a where clause which is why your orWhere isn’t working. In v3 you can try modifying the base query: https://filamentphp.com/docs/3.x/tables/filters#modifying-the-base-query I don’t think this exists in v2…you could try to manipulate the eloquent query and only apply it base on a filters state.
whatsisname
whatsisnameOP15mo ago
thanks for your input. I am planning to upgrade to v3 asap, and I was hoping there would be a solution for this, so i will try out the baseQuery() method. Other than that, I've been thinking about this Issue a bit, and since it is a "filter" to "filter" the existing results it totally does make sense that your custom query is wrapped into an AND condition since it is not the use-case of a filter to add additional entries to a result set. But I still hope, that I somehow can work with the baseQuery method.
Want results from more Discord servers?
Add your server