-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
validateBoolean is not working with verbose "true" parameter via browser #18563
Comments
I modified the If you dump the response on the the server side - are you sure you are getting a If you are getting a string representation of |
Yeah - this probably means your not getting a true boolean in the request - it is being converted to a string somewhere. Probably best to have your javascript send Any further issues feel free to discuss on the forums on in LaraSlack and I'll try and help out. |
I am using xdebug, and see, that there is string, not casted value. yes, it works with 1,0, but I hope that true/false also works :/ |
It is not converted to string at all. All values passed through get/post (except php unit tests) are in string representation. So I don't know what reason to keep |
your ajax is going to send a string unless you send 0 or 1. I have my form request base class setup to cast |
I meant you are sending a
The booleans could come from elsewhere (such as manually cast). There is no need to remove them, as it doesnt negatively affect anything.
The problem is if you allow $user->accepted = "false". Which in the database will be saved as
You can write you own route middleware to do the cast, or do as @devcircus says and cast it yourself on the form request. We cant add a global middleware to always convert |
I meant, that all values from the form are in the same representation, without any casting from string to boolean, and then from boolean to string again. Actually only string value is passed to
I understand negative aspects if there would be And yes, I have my own castings as @devcircus mentioned, but validation doesn't call them, because |
btw: #18141 there was changed ValidationRuleParser, so I believe that casting to boolean should work also in that way |
@webmake. You could do something like this: #17010 The issue around validation and casting has been discussed many times such as #14467, #15920 and #17010 I suggest looking at the comments from the Laravel team there, and perhaps discuss this further - there is a Laravel/Internals discussion about it here: laravel/ideas#42 |
Closing this issue then, please refer to @laurencei's comment. |
I think this would be best solution for booleans, http://stackoverflow.com/a/15075609 it covers most of cases
Currently I solved this issue like:
|
Well final solution was to send as json content type, without |
Description:
Boolean validation seems failing, because value is "true" not true, with message "The parameter field must be true or false."
Steps To Reproduce:
$.post('http://appurl.dev/post', { parameter: true})
Maybe I missed something, for example casting or other middleware, or is it bug? Testing application with phpunit tests this problem won't occur, only via browser requests
The text was updated successfully, but these errors were encountered: