Reputation: 764
How can I add correctly custom validation rule in Laravel 5?
In Laravel 4 it was placed in some autoloaded file:
Validator::register('alpha_spaces', function($attribute, $value)
{
return preg_match('/^([-a-z0-9_-\s])+$/i', $value);
});
Upvotes: 1
Views: 3498
Reputation: 1657
You can check the documentation: http://laravel.com/docs/5.0/validation#custom-validation-rules
Validator::extend('foo', function($attribute, $value, $parameters) {
return $value == 'foo';
});
I think you only need to change 'register' with 'extend'.
Upvotes: 3