Laravel 5 Validation Trim

后端 未结 8 926
梦谈多话
梦谈多话 2020-12-18 05:23

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).

8条回答
  •  执念已碎
    2020-12-18 05:52

    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(...);
    

提交回复
热议问题