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

Having `orWhereHas` in initial query cancels out filters #793

Closed 7Jhanson closed 2 years ago

7Jhanson commented 2 years ago

I have something like:

QueryBuilder::for(Object::class) ->whereHas('comments')->orWhereHas('relation.comments')->orWhereHas('relation.relationChild.comments') ->allowedFilters($this->setAllowedFilter($this->filters)) ->allowedSorts($this->setAllowedSorts($this->filters)) ->paginate(data_get($options, 'pagination.rowsPerPage'), ['*'], 'page', data_get($options, 'pagination.page'));

when adding the ->orWhereHas('relation.comments')->orWhereHas('relation.relationChild.comments')

the filters don't work anymore, because the package uses whereHas.

Any solutions to make it so I can use orWhereHas and filter at the same time?