In app/Exceptions/Handler.php you add the convertValidationExceptionToResponse
function to overwrite the default (see the original from https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/Exceptions/Handler.php#L416 )
That gives you the option to customize the output to the format that you want. I hope this is a good starting point for you :)
a-h-abid liked this reply
Hey thank @Tobias, that is a good start point, but that way I wont be able to get to know for which rule the message is for.
Anyway I kind of digged down the source code and this is what I came up with.
I created a middleware on which I set my own validator as the validator resolver. The validator also extends the laravel's validator. With your help from example above, I modified my validator to get my desired response.
Currently it works well for API responses. But may not work well in blade view files due to MessageBag class. Maybe someone finds a better implementation someday. Or maybe even added in Core.
iboldurev, tvbeek liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community