spatie / laravel-query-builder

Easily build Eloquent queries from API requests
https://spatie.be/docs/laravel-query-builder
MIT License
4.02k stars 395 forks source link

Bugfix ignore allowed filters #818

Closed davidjr82 closed 1 year ago

davidjr82 commented 1 year ago

Currently ignored filters values option is working wrong because the function resolveValueForFiltering is using array_diff_assoc that computes the difference of arrays with additional index check (see PHP docs).

This means that to ignore a filter, both value and key must match to be ignored. As filters are passed by GET params, they can be in a different order or have a non predictable index.

To ignore a value we need to match only the value without cheking the index, so php array_diff function is the right choice here.

I have modified an existing test to ignore the second option instead the first one to raise the error, and I have added one more test before commiting the bugfix.

AlexVanderbist commented 1 year ago

Awesome, can't believe this has gone unnoticed for so long. Thanks!

stevebauman commented 1 year ago

Unfortunately this PR has broken a use-case for me in https://github.com/spatie/laravel-query-builder/issues/826.