Skip to content

Instantly share code, notes, and snippets.

@ijasxyz
Last active November 1, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijasxyz/f66bcf9492f83d7d99e9729aa0bdfdd6 to your computer and use it in GitHub Desktop.
Save ijasxyz/f66bcf9492f83d7d99e9729aa0bdfdd6 to your computer and use it in GitHub Desktop.
Trim all input values in Laravel 4
<?php
/*
* In Laravel Filters...
*/
App::before(function (\Illuminate\Http\Request $request)
{
$request->merge(
array_map_recursive(
"trim",
array_except(
$request->all(),
["password", "password_confirmation"]
)
)
);
});
<?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