Skip to content

[13.x] Clarify orWhere with array propagates boolean to inner conditions#11178

Open
scabarcas17 wants to merge 1 commit intolaravel:13.xfrom
scabarcas17:clarify-orwhere-array-boolean
Open

[13.x] Clarify orWhere with array propagates boolean to inner conditions#11178
scabarcas17 wants to merge 1 commit intolaravel:13.xfrom
scabarcas17:clarify-orwhere-array-boolean

Conversation

@scabarcas17
Copy link
Copy Markdown

Body del PR sugerido:
Closes laravel/framework#59516 (in spirit — that issue requests documentation, per @crynobone's comment).

This clarifies a footgun introduced in laravel/framework#53147 (Laravel 11.28) where orWhere with array syntax propagates the or boolean to
every condition inside the group, rather than joining the inner conditions with and as users naturally expect.

Three small additions:

  1. A new [!NOTE] right after the array-of-conditions example showing the actual SQL produced and pointing readers to the closure-based grouping.
  2. Expanded the existing [!WARNING] in the Or Where Clauses section to explicitly mention the array-syntax behavior (not just global scopes).
  3. Same expansion applied to the duplicate warning in the Logical Grouping section.

No code changes; documentation only.

Copilot AI review requested due to automatic review settings May 1, 2026 21:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documentation-only update to the Query Builder docs clarifying the behavioral “footgun” where orWhere with array syntax applies the outer or boolean to every inner condition, and pointing readers toward closure-based grouping to get AND-joined inner clauses.

Changes:

  • Added a [!NOTE] explaining the SQL behavior of orWhere([...]) with an example and a link to closure-based grouping.
  • Expanded the existing [!WARNING] blocks (in both “Or Where Clauses” and “Logical Grouping”) to mention the array-syntax behavior in addition to the existing global-scope warning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread queries.md
```

> [!NOTE]
> When this array syntax is used with `orWhere`, the inner conditions inherit the outer `or` boolean. For example, `->orWhere([['a', 1], ['b', 2]])` produces `or ("a" = 1 or "b" = 2)`, not `or ("a" = 1 and "b" = 2)`. To group `or` conditions with `and` between the inner clauses, pass a closure to `orWhere` instead — see [Or Where Clauses](#or-where-clauses) below.
Comment thread queries.md

> [!WARNING]
> You should always group `orWhere` calls in order to avoid unexpected behavior when global scopes are applied.
> You should always group `orWhere` calls using a closure — both to avoid unexpected behavior when global scopes are applied, and because passing an array directly to `orWhere` propagates the `or` boolean to every condition inside the group rather than joining them with `and`.
Comment thread queries.md

> [!WARNING]
> You should always group `orWhere` calls in order to avoid unexpected behavior when global scopes are applied.
> You should always group `orWhere` calls using a closure — both to avoid unexpected behavior when global scopes are applied, and because passing an array directly to `orWhere` propagates the `or` boolean to every condition inside the group rather than joining them with `and`.
@scabarcas17 scabarcas17 closed this May 1, 2026
@scabarcas17 scabarcas17 deleted the clarify-orwhere-array-boolean branch May 1, 2026 21:39
@scabarcas17 scabarcas17 restored the clarify-orwhere-array-boolean branch May 1, 2026 21:52
@scabarcas17 scabarcas17 reopened this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent orWhere behavior after upgrade from Laravel 10.x to 13.x

2 participants