Skip to content

Conversation

@yousefkadah
Copy link

Issue: #53628 - orWhere() with array syntax was generating OR between array items instead of AND.
The Bug
->where('status', 'Queued')
->orWhere([
['status', '=', 'On Water'],
['checkout_date', '!=', '']
])
Was generating (WRONG):
WHERE status = ? OR (status = ? OR checkout_date != ?)
Now generates (CORRECT):
WHERE status = ? OR (status = ? AND checkout_date != ?)
🔧 The Fix
Modified Builder.php:928-939 to remove the $boolean parameter from individual array items. Now the $boolean only controls how the group connects to previous clauses, not how items inside the array are joined.
This pull request updates the handling of array-based conditions in the query builder, specifically changing how multiple conditions within an array are combined. Previously, these conditions were joined using the OR operator, but now they are joined using the AND operator. This affects both the query generation logic and the associated tests to ensure consistent results.

This fixes a regression where `orWhere()` with array syntax was incorrectly
joining multiple array conditions with OR instead of AND, breaking backward
compatibility from Laravel 5.4+.

**Problem:**
```php
->where('status', 'Queued')
->orWhere([
    ['status', '=', 'On Water'],
    ['checkout_date', '!=', '']
])
```

Previously generated (correct):
```sql
WHERE status = ? OR (status = ? AND checkout_date != ?)
```

After regression, generated (incorrect):
```sql
WHERE status = ? OR (status = ? OR checkout_date != ?)
```

**Root Cause:**
The `addArrayOfWheres()` method was passing the `$boolean` parameter ('or')
to each individual condition inside the array, when it should only control
how the entire group connects to previous clauses.

**Solution:**
Array items are now always joined with AND (the natural behavior of "where"),
while the `$boolean` parameter only controls how the nested group connects
to the rest of the query.

Fixes laravel#53628

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@ahinkle
Copy link
Contributor

ahinkle commented Oct 23, 2025

See #53197

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.

3 participants