dongshu7162 2018-04-10 17:08
浏览 31

之前:18年前Laravel验证器消息无法正常工作

I'm very new to Laravel. So please go easy on me.

I'm having this message for "before:18 years ago" date validator.

The "" must be a date before 18 years ago.

How can I customize it ? Do I need to compile something ?

I have this in my validation.php which is in the resources/lang/en/

'custom' => [
    'dob' => [
        'before' => 'Invalid Age'
    ],
 ],

I'm using a FormBuilder

https://pyrocms.com/help/developer-tools/form-builders/creating-a-form-builder

'dob' => [
        'type'   => 'anomaly.field_type.datetime',
        'config' => [
            "mode"          => "date",
            "date_format"   => "j F, Y",
             "year_range"    => "-100:-18",
             ],
        'rules'  => [
            'required','before:18 years ago' 
         ],

       ],
  • 写回答

2条回答 默认 最新

  • douwei2713 2018-04-10 19:21
    关注

    You can customize validation messages by specifying attributes within the message text:

    $messages = [
        'dob' => 'The :attribute must be a date before 18 years ago.',
    ];
    

    When passed to a validator instance the :attribute placeholder will be substituted.

    $validator = Validator::make($input, $rules, $messages);
    

    Using language files, you define the message text the same:

    'custom' => [
       'dob' => [
           'before' => 'The :attribute must be a date before 18 years ago.'
       ],
    ],
    

    and then optionally give the attribute a custom name:

    'attributes' => [
        'dob' => 'date of birth',
    ],
    

    You may retrieve lines from language files using the __ helper function. The __ method accepts the file and key of the translation string as its first argument.

    Custom Validation Error Messages

    Localization

    评论

报告相同问题?