Skip to content

[13.x] Compare fluent database rule where() values literally - #62425

Merged
taylorotwell merged 1 commit into
13.xfrom
13.x-fluent-database-rule-wheres
Nov 11, 2026
Merged

taylorotwell merged 1 commit into
13.xfrom
13.x-fluent-database-rule-wheres

Conversation

@pushpak1300

Copy link
Copy Markdown
Member

Fluent Rule::exists() and Rule::unique() rules write their where() conditions into the string rule format, and the validator parses them back. Some values do not survive that round trip. For example, ->where('status', 'NULL') runs whereNull('status'), and ->where('code', '!abc') runs code != 'abc'.

The validator now reads the conditions from the rule object, so where() always compares the value literally. whereNull(), whereNotNull() and whereNot() work as before, and (string) $rule does not change.

Note

A custom presence verifier receives a closure in $extra for a where() value of NULL or NOT_NULL, or one that starts with !. Other values arrive as before.

@pushpak1300
pushpak1300 marked this pull request as ready for review November 11, 2026 13:22
@taylorotwell
taylorotwell merged commit ef1821b into 13.x Nov 11, 2026
65 checks passed
@taylorotwell
taylorotwell deleted the 13.x-fluent-database-rule-wheres branch November 11, 2026 14:21
SanderMuller added a commit to SanderMuller/laravel-fluent-validation that referenced this pull request Nov 13, 2026
laravel/framework#62425 and #62426 (not yet tagged) store the where
clauses of a database rule with an operator and compare the values
literally. The batch query read only the old shape, so it dropped
whereNull() and withoutTrashed() conditions, and soft-deleted rows passed
exists (#30).

The batched results were also keyed by table and column only. Rules with
a different where clause, connection or ignored id, plain fields on the
same column, and rules added in withValidator() read each other's results.
Invalid input could pass and valid input could fail.

The batch also compared the stored values to the input in PHP. On a
case-insensitive collation or an integer column, the result differed from
Laravel. For example, on MySQL, unique let ALICE@example.com pass when
alice@example.com existed.

- Read both where shapes.
- Key each batched result by the exact presence-verifier call that Laravel
  makes. Use the real verifier for any other call, for any value the batch
  did not query, and for array values (getMultiCount()).
- Let the database compare each value, so the batch matches the collation
  and type rules that Laravel's own query uses.
- Run one query for fields that run the same query, in any where order.
- Keep a rule per item when Laravel passes its conditions as closures.

Fixes #30

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
binaryfire added a commit to hypervel/components that referenced this pull request Nov 15, 2026
Honor queryCallbacks overrides and avoid reconstructing conditions discarded by custom database rules. Compare native stored conditions directly so equivalent Data rules can share validation without losing callback identity or repeated predicates.

Keep boolean JSON candidates native in scalar presence checks and group boolean alternatives in array checks. Ordinary candidates retain their existing query and binding behavior.

Corrects adaptations of laravel/framework#62425, #62447, #62442 and #62459 at c980cb5827c6512c12ac44493d172a593b41299a. Parser, Data and affected SQLite, PostgreSQL, MySQL and MariaDB validation tests pass, as do full static analysis and formatting.
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.

2 participants