使用dingoapi进行表单请求验证

时间:2016-08-10 11:05:07

标签: laravel laravel-5

当我在CustomRequest类中扩展dingoapi FormRequest类时,对于"消息"字段我收到此默认消息。

 {
  "message": "422 Unprocessable Entity",
  "errors": {
    "email": [
      "The email has already been taken."
    ]
  },
  "status_code": 422
}

如何覆盖此消息字段?

1 个答案:

答案 0 :(得分:3)

Form Request课程中,您可以覆盖名为messages的方法,并根据每条规则将信息放在那里:

public function messages() {
       return [
            'name.required' => 'Please, provide me with your name',
            'email.required' => 'Email address is mandatory',
            'email.unique' => 'This email is already in our database'
        ]
    );
}