Skip to content

[13.x] Compare integers and booleans as strings in the database presence verifier - #62447

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
pushpak1300:fix-presence-verifier-scalar-comparison
Nov 12, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
pushpak1300:fix-presence-verifier-scalar-comparison

Conversation

@pushpak1300

Copy link
Copy Markdown
Member

exists and unique results depend on how the input arrives. For a varchar column holding alpha and 007, on MySQL and MariaDB:

Input Rule Before After
"0" (form) exists:invites,code fails fails
0 (JSON) exists:invites,code passes fails
false (JSON) exists:invites,code passes fails
7 (JSON) exists:invites,code passes, matches 007 fails
0 (JSON) unique:invites,code fails passes

The presence verifier passes integers to the query builder as they are, so they are bound as integers, and MySQL then compares the string column as a number. Form input is always a string, so the same value gives a different result.

DatabasePresenceVerifier now compares integers and booleans as strings, the way they arrive from a form. Booleans become '1' and '0', the values Laravel already binds for them. Integer, boolean and decimal columns still match: exists:users,id with 1 passes on MySQL, MariaDB, PostgreSQL and SQLite. Custom presence verifiers receive the same values as before.

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