2015-04-18 80 views
2

我想在laravel5表单验证错误消息中设置自定义的提交名称。在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; 
    } 

} 

这里的时候,老,新和cnew emty,错误信息会像下面,需要

  • 老场。
  • 新字段是必填字段。
  • 需要cnew字段。需要

我想显示像下面而不是上面的消息,

  • 旧密码字段
  • 新密码字段需要
  • 确认密码字段是必需的。

如何在laravel5 Form Request Validation方法中可能?

回答

2

选项1:

您可以定义自定义属性的资源/郎/ 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' 
    ] 
+0

这是需要的,谢谢:) – gsk