-
Notifications
You must be signed in to change notification settings - Fork 253
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
[Question] Boolean values casted to string #340
Comments
Would |
@bakerkretzmar Indeed, while Generally speaking, boolean |
I think for query strings your best bet is to do this formatting yourself. There's no way to actually send it as a boolean because everything in the query string is a string. It looks like people have asked about this in the If you want to use the $request->merge(['body' => $request->boolean('body')]);
// now $request->input('body') is a boolean
$request->validate(...); |
@bakerkretzmar The fact that the discussion in still ongoing since 5 years on I personally think that the purpose of serialization is to keep at least a boolean value. IMO, Back to Ziggy, being a bridge (I don't mean to reduce Ziggy to "a bridge") between Laravel and qs, should it blindly bridge these 2 projects or should it bridge with sugar syntax? Knowing that Laravel may never validate "true" and "false" strings as being booleans, isn't it Ziggy's responsibility to implement an encoder, translating boolean strings to 0 and 1? Still IMO, this is an issue 90% of users using boolean validation would face, while I don't see any downside to it |
Actually, I think you might be right. My main goal for Ziggy's <?php
route('collector.get-messages', [
'body' => true,
'collector' => 1,
]);
// returns
"http://example.com/collector/1/messages?body=1" Unfortunately we'll have to implement our own encoder and decoder to pass to If you're already working on a PR for this or you want to, that would be awesome! (Please target the |
If Laravel’s route didn’t change Boolean values to an int, I would have been surprised ^^’ I would happily submit a PR, I will to read about encoders on Thanks for the debate |
Sorry for the delay, I got stuck on projects and couldn't look at it for now. |
No worries! I got it working, it'll be included in v1. |
Considering the following example code:
It's currently (
v0.9.4
) rendered as: http://example.com/collector/1/messages?body=trueIn PHP it's considered to be a string, and both
"true"
and"false"
strictly equals to the boolean valuetrue
. I think this comes from theqs
dependencystringify()
function, if I want to send a PR, should I send it to this repository, or toqs
?The text was updated successfully, but these errors were encountered: