core icon indicating copy to clipboard operation
core copied to clipboard

Support for NOT / invert / exclude in SearchFilter (may also other filters)

Open Ninos opened this issue 3 years ago • 0 comments

The only feature I'm missing for SearchFilter is the possibility to invert the query. For example searching for names which do not partially match with a string.

This could be done manually, e.g.:

#[ApiFilter(SearchFilter::class, properties: [
    '!name' => 'exact|partial|whatever',
])]

or

just add !${property} to every defined filter as new inverse filter rule. e.g.:

#[ApiFilter(SearchFilter::class, properties: [
    'name' => 'exact|partial|whatever',
])]

allows ?name=SOMETHING and also ?!name=SOMETHING. If you cannot use ! for query param prefix, may use _ instead?

I think the second solution is a bit more elegant. Why you shouldn't allow inverse queries if "normal" filters are already allowed? For me there's no security reason to not enable it globally.

Same could be done e.g. with DateFilter, RangeFilter

Ninos avatar May 15 '22 20:05 Ninos