Note: This solution won't work if any of your inputs are arrays (such as "data[]").
You may try this, trim using this one line of code before validation:
Input::merge(array_map('trim', Input::all()));
Now do the rest of your coding
$username = Input::get('username'); // it's trimed
// ...
Validator::make(...);
If you want to exclude some inputs from trimming then you may use following instead if all()
Input::except('password');
Or you may use
Input::only(array('username'));
Update: Since Laravel 5.4.*
inputs are trimmed because of new TrimStrings
middleware. So, no need to worry about it because this middleware executes on every request and it handles array inputs as well.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…