2015-04-18 93 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