Skip to content
Advertisement

Combine validation errors and return one single message

I have two arrays I want to validate in my custom Request:

JavaScript

This returns an error message per each word. But I want a single general message like “Some of the words are invalid”. Is there any Laravel-way to do this?

Advertisement

Answer

You could do this:

JavaScript

EDIT:

I think I may have found a solution:

First, make sure you import both Validator and HttpResponseException at the top:

JavaScript

Then, you can override the native failedValidation method and alter your errors however you want:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement