Inconsistencies in how boolean request fields are handled #53276
Unanswered
navaneeth-raman-bhaskar
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
GET
When using the GET request, Boolean validation can fail because form inputs from a GET request are often treated as strings, and Laravel's built-in boolean validation rule is strict, accepting only
true
,false
,"1"
,"0"
,1
, and0
.The following will fail for the URL
https://your-dns/api/users?active=true
POST
The Boolean validation rule only allows
true
,false
,1
,0
,"1",
and"0"
values. It doesn't handle strings like'yes'
,'no'
,'on'
, or'off'
by default. However,$request->boolean('active')
can transform those values into booleantrue
orfalse
.Laravel's request validation Declined validates
"no"
,"off"
,0
,"0"
,false
, or"false"
while Accepted validates"yes"
,"on"
,1
,"1"
,true
, or"true".
However, there is no built-in accepted_or_declined rule to handle both at once.Beta Was this translation helpful? Give feedback.
All reactions