How to specify the default error message when extending the Validation class in Laravel 4 -


i use made use extend function extend , adding custom rules on validation class of laravel 4.

validator::extend('foo', function($attribute, $value, $parameters) {     return $value == 'foo'; }); 

when validate rule using newly created custom extension, returns validation.foo if rule fails. there way define generic/ default message when extending validation class in laravel 4?

the laravel 4 docs state need define error message custom rules.

you have 2 options;

option 1:

$messages = array(     'foo' => 'the :attribute field foo.', );  $validator = validator::make($input, $rules, $messages); 

option 2:

specify custom messages in language file instead of passing them directly validator. so, add messages custom array in app/lang/xx/validation.php language file:

'custom' => array(     'foo' => array(         'required' => 'we need know foo!',     ), ), 

Comments