Can I attach after validation hook (documentation) to my custom made request with php artisan make:request
?
Asked
Active
Viewed 2,069 times
7

Marcin Nabiałek
- 109,655
- 42
- 258
- 291

Norgul
- 4,613
- 13
- 61
- 144
1 Answers
11
You can override getValidatorInstance()
method in your custom request class like this:
protected function getValidatorInstance()
{
$validator = parent::getValidatorInstance();
// here you can apply hook (example hook taken from documentation):
$validator->after(function ($validator) {
if ($this->somethingElseIsInvalid()) {
$validator->errors()->add('field', 'Something is wrong with this field!');
}
});
return $validator;
}

Marcin Nabiałek
- 109,655
- 42
- 258
- 291