Laravel 5 Validation Trim

后端 未结 8 938
梦谈多话
梦谈多话 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 06:01

    You can use this in your request file.

    $input = request()->all();
    $input['url'] = trim($input['url']);
    request()->replace($input);
    

    You can also create an all() function in your request file to update request parameters:

     public function all()
        {
            $all = parent::all(); // $this->all();
            $all['new_key'] = "new_data";
            $all['old_key'] = "new_data";
    
            return $all;
        }
    

提交回复
热议问题