Laravel 5.6 表单请求验证

Laravel 5.6 FormRequest validation

我有一组输入字段需要验证。在验证发生之前,我删除了逗号(因为用户输入逗号作为千位分隔符)。但它仍然抱怨该数字不是数字。

class UpdateFamilyExpense extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function sanitize()
    {
        $attributes = $this->all();

        for ($i=1; $i<=15; $i++)
        {
            $attributes['e'.$i] = str_replace(',', '', $attributes['e'.$i]);
        }
        $this->replace($attributes);
    }

    public function rules()
    {
        $this->sanitize();

        return [
            'e1' =>    'required|numeric',
        ];
    }

    public function messages()
    {
        return [
            'e1.required' => 'required',
            'e1.numeric' =>  'must be a numeric',
        ];
    }
}

我不知道我哪里错了。有人可以帮我弄清楚我在这里缺少什么吗?

prepareForValidation 重写为:

protected function prepareForValidation()
{
    $this->sanitize();
}