I am a beginner in Laravel 5.
How can I remove whitespaces in validator?? i have read the documentation but there is no validator for trim(remove whitespaces).
here my rules
$rules = [
'name' =>'required',
'email' => 'required|email',
'address' => 'required',
'phones' => 'required'
];
thanks for your answer.
You can use the following code to trim all string input (as you might have arrays in the input)
// trim all input
Input::merge(array_map(function ($value) {
if (is_string($value)) {
return trim($value);
} else {
return $value;
}
}, Input::all()));
It's not job for validator to change any input data. Trim validator exists in CodeIgniter, but as to me this isn't right place to perform trim.
You can automatically trim all input by using using this:
Input::merge(array_map('trim', Input::all()));
Now do the rest of your coding:
$username = Input::get('username'); // it's trimed
// ...
Validator::make(...);
Due to the documention laravel HTTP Request by default laravel trim all the requests data.
and Trim
the request in validation part is so dirty job.
You could manage this feature like trim
or convert empty string to null
with the middleware
because middleware execute before the validation and you could have clean data in validation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With