I am using form request validation method for validating request in laravel 5.I would like to add my own validation rule with form request validation method.My request class
Using Validator::extend() like you do is actually perfectly fine you just need to put that in a Service Provider like this:
app['validator']->extend('numericarray', function ($attribute, $value, $parameters)
{
foreach ($value as $v) {
if (!is_int($v)) {
return false;
}
}
return true;
});
}
public function register()
{
//
}
}
Then register the provider by adding it to the list in config/app.php:
'providers' => [
// Other Service Providers
'App\Providers\ValidatorServiceProvider',
],
You now can use the numericarray validation rule everywhere you want