Support the ongoing development of Laravel.io →
Validation
Last updated 1 month ago.
0

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/F... )
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 :)

1

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.

2

Sign in to participate in this thread!

LoadForge

Your banner here too?

a-h-abid a-h-abid a-h-abid Joined 17 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.