我想在laravel5表单验证错误消息中设置自定义字段名称。
我的form validation request class
是,
class PasswordRequest extends Request {
protected $rules = [
'old' => ['required'],
'new' => ['required','same:cnew'],
'cnew' => ['required']
];
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() {
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules() {
return $this->rules;
}
}
这里当old,new和cnew emty,错误信息将如下,
我希望显示如下,而不是上面的消息,
如何在laravel5表单请求验证方法中使用?
答案 0 :(得分:3)
选项1:
您可以在 自定义验证属性 '属性'下的资源/ lang / en / validation.php中定义自定义属性。 => [],像这样:
/*
|--------------------------------------------------------------------------
| Custom Validation Attributes
|--------------------------------------------------------------------------
|
| The following language lines are used to swap attribute place-holders
| with something more reader friendly such as E-Mail Address instead
| of "email". This simply helps us make messages a little cleaner.
|
*/
'attributes' => [
'old' =>'Old Paaword',
'new' =>'New password',
'cnew' =>'Confirmation password'
]