Last active
November 1, 2016 10:07
-
-
Save ijasxyz/f66bcf9492f83d7d99e9729aa0bdfdd6 to your computer and use it in GitHub Desktop.
Trim all input values in Laravel 4
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 | |
/* | |
* In Laravel Filters... | |
*/ | |
App::before(function (\Illuminate\Http\Request $request) | |
{ | |
$request->merge( | |
array_map_recursive( | |
"trim", | |
array_except( | |
$request->all(), | |
["password", "password_confirmation"] | |
) | |
) | |
); | |
}); |
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 | |
/* | |
* In Laravel helpers... | |
*/ | |
function array_map_recursive($callback, $array) | |
{ | |
foreach ($array as $key => $value) { | |
if (is_array($array[$key])) { | |
$array[$key] = array_map_recursive($callback, $array[$key]); | |
} else { | |
$array[$key] = call_user_func($callback, $array[$key]); | |
} | |
} | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment