2016-06-16 5 views
1

私のAppServideProviderのブート方法で、キリル文字用のカスタム検証ルールを設定しました。これは、次のようになります。Laravel 5.2 - バリデーションを拡張するときにカスタム検証メッセージを作成

public function boot() 
{ 
    Validator::extend('cyrillic', function ($attribute, $value, $parameters, $validator) { 
     return preg_match('/[А-Яа-яЁё]/u', $value); 
    }); 
} 

期待どおりに動作します。しかし、ラテン入力のために検証が合格しなければ、私はエラーメッセージ 'validation.cyrillic'を得ます。どうすれば修正できますか?カスタムメッセージを「キリル文字」の検証ルールに渡すにはどうすればよいですか?

答えて

1

グローバルに定義する場合は、resources/lang/LANG/validation.phpにある検証ファイルを編集する必要があります。ここで、LANGは定義する言語です。

たとえば、英語の場合はresources/lang/en/validation.phpというファイルを開き、次のようなメッセージを追加します。

return [ 
    'accepted'    => 'The :attribute must be accepted.', 
    'active_url'   => 'The :attribute is not a valid URL.', 
    // Add yours to somewhere in the first level of the array 
    'cyrillic'    => 'The :attribute is not Cyrillic.' 
] 

ローカルでは、リクエスト内で定義できます。

public function messages() 
{ 
    return [ 
     'cyrillic' => 'The :attribute is not Cyrillic.' 
    ]; 
} 
+0

チャームのように働いた。乾杯! – Codearts

関連する問題