2016-07-07 5 views
0

によってあなたがタイプdateの二つのフィールド持って与えられる形に仮定します誕生日運転免許証を。フォームは、フィールドで検証メッセージを要求していないタイプ

<?php 
public function rules() { 
    return [ 
     'birthday' => 'required|date', 
     'driver_license_date' => 'required|date' 
    ]; 
} 

しかし、私はこのように私のカスタムメッセージたい:さて、私はLaravelは以下のルールでの日付の検証を処理させたいと思い、私は:attribute魔法の変数について知っ

<?php 
public function messages() { 
    return [ 
     'birthday.required' => 'Please fill up your birthday', 
     'driver_license_date.required' => 
      'Please fill up the date that your Driver License was issued', 
     'birthday.invalid' => 
      'Your birthday date is invalid', // <-- This doesn't work 
     'driver_license_date.invalid' => 
      'The date for the driver license provided is invalid', // <-- This doesn't work 


     'date' => 'Invalid date', // <-- This works, but its one message for both fields 
    ]; 
} 

をし、これは架空のシナリオケースですが、私は互いに関係のない同じタイプの2つのフィールドを検証する必要がある正当な問題があります。私は自分のユーザーにメッセージを提供できるようにしたいのですが、メッセージは各フィールドに固有であり、タイプによっては一般的ではありません。

これは可能ですか?

答えて

1

あなたは、この使用することができます:

public function messages() { 
    return [ 
     'birthday.required' => 'Please fill up your birthday', 
     'driver_license_date.required' => 'Please fill up the date that your Driver License was issued', 
     'birthday.date' => 'Your birthday date is invalid', 
     'driver_license_date.date' => 'The date for the driver license provided is invalid' 
    ]; 
} 
+0

は、質問の答えを受け入れるように私のための10分前のことが必要であり、ありがとうございます。 –

+0

歓迎です...問題ありません;) –

関連する問題