[英]Set custom validation message for field in laravel5 form validation?
I want to set custom filed name in laravel5 form validation error messages. 我想在laravel5表单验证错误消息中设置自定义文件名。
my form validation request class
is, 我的
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;
}
}
Here when old,new and cnew emty, Error message will be like following, 在这里,当旧的,新的和新的空时,错误消息将如下所示,
I want to display like following instead of above message, 我想显示如下而不是上面的消息,
How it is possible in laravel5 Form Request Validation method? laravel5表单请求验证方法中怎么可能?
Option 1: 选项1:
You can define your custom attributes in resources/lang/en/validation.php under Custom Validation Attributes 'attributes' => [], like so: 您可以在resources / lang / en / validation.php中的Custom Validation Attributes'attributes '=> []下定义您的自定义属性,如下所示:
/*
|--------------------------------------------------------------------------
| 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'
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.