0

I have a multi-step form and each step with its own FormRequest for validating fields.

All works fine but I need to make some extra actions in case one field is not validated.

So, if the FormRequest results in an error, the controller is bypassed and returned to the view showing errors.

In my case, I have a validation rule for title. In case title exists in database, I need to run some extra PHP code.

How can I accomplish this?

David
  • 166
  • 1
  • 10
Apalabrados
  • 1,098
  • 8
  • 21
  • 38

1 Answers1

0

You can override the validationFailed method in your FormRequest and check which field failed the validation.

protected function failedValidation(Validator $validator)
{
    if (in_array('title', $validator->failed())) {
        // TODO
    }

    // You could also check individual errors with $validator->errors()

    parent::failedValidation($validator);
}
Olivenbaum
  • 971
  • 1
  • 6
  • 17