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 is given below.I want to add custom validation numeric_array with field items.
protected $rules = [
'shipping_country' => ['max:60'],
'items' => ['array|numericarray']
];
My cusotom function is given below
Validator::extend('numericarray', function($attribute, $value, $parameters) {
foreach ($value as $v) {
if (!is_int($v)) {
return false;
}
}
return true;
});
How can use this validation method with about form request validation in laravel5?
All answers on this page will solve you the problem, but... But the only right way by the Laravel conventions is solution from Ganesh Karki
If you want to create validation by Laravel conventions follow this tutorial. It is easy and very well explained. It helped me a lot.
Tutorial link
You need to override
getValidatorInstance
method in yourRequest
class, for example this way: