-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.x] Add boolean($key) method to Request #31160
Conversation
boolean method added
Add tests for boolean method
What made you want to use FILTER_NULL_ON_FAILURE? |
Honestly I did not want to at first, but figured if the value is something entirely different than a Boolean (“hello world”) then it probably shouldn’t be one? But I don’t know. Personally I never use it myself but thought I’d hear screams if not used, haha. — edit — So I am 100% up for removing that! |
Personally I would remove it. It adds a third value that this function can return which gives the user more situations to consider, etc. |
Very good point! I’ll modify |
Could you send us a PR to the laravel/docs repository (6.x branch). Thanks. |
Thanks! Let me know if wording etc. should be improved |
this is a general comment - ignore if not suitable - in another PR the tester used a php annotation
wheras here its being done 5/6 times in the test - is there concern for consistency or it doesnt matter? |
What is the point of this while we don't allow string values like "on"/"off" inside validation? |
Simplify the code I guess? But yes I agree that would be nice too
|
@LasseRafn How this simplifies the code while the validator doesn't accept "false", "true", "on", "off", string values? also, in PHP, values like, 0, 1, "0", "1", can be considered as booleans, which are already accepted by the validator. |
It simplifies getting values as a Boolean. Instead of doing filter_var($value, FILTER_VALIDATE_BOOLEAN) on the request value
|
This PR introduces a new helper method to the
Illuminate\Http\Request
:boolean($key)
which takes input using theinput()
method and filters it through filter_var andFILTER_VALIDATE_BOOLEAN
Brief about
FILTER_VALIDATE_BOOLEAN
from php.net:I set the default to be
false
so than an undefined variable (eg unchecked checkbox) would act as false.Unsure how everyone feels about this and the naming of it though.
(edit: removed references to FILTER_NULL_ON_FAILURE as it was removed from the code)