Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iPurpl3x's avatar

Reorder clauses of existing Query Builder instance

Hi I would need to reorder the clauses of a query builder instance. In my situation I have to extend an existing query that is coming from some code that is not mine and I cannot change.

I have the problem that I want to do some filtering and with my whereNotExists() call this doesn't work because it gets appended to the end of the query and there are some OR WHERE clauses before that so the last AND WHERE that I inserted doesn't apply to the whole query but only to the last OR WHERE part of it.

So I would like to find a way to insert my filtering clause before the OR WHERE clauses that are already present in the query.

Is there a way to do this?

0 likes
1 reply
iPurpl3x's avatar

I ended up finding a workaround for my original problem that did not involve changing the order of the clauses in the query.

It would still be interesting to know if such a thing is possible...

Please or to participate in this conversation.