Last active
December 27, 2020 03:13
-
-
Save afiqiqmal/ca07ae3dad0be70e9691ce861633c236 to your computer and use it in GitHub Desktop.
Middleware of Laravel to Convert Incoming Request contain boolean string to boolean. Kinda head ache when laravel didn't detect boolean string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BooleanStringConverter extends TransformsRequest | |
{ | |
protected function transform($key, $value) | |
{ | |
if (in_array($key, $this->except, true)) { | |
return $value; | |
} | |
if (is_string($value)) { | |
if ($value == 'true') { | |
return true; | |
} | |
if ($value == 'false') { | |
return false; | |
} | |
} | |
return $value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment