The default ValidationException looks like this (source: Laravel Official documentation)
{
"message": "The team name must be a string. (and 4 more errors)",
"errors": {
"team_name": [
"The team name must be a string.",
"The team name must be at least 1 characters."
],
"authorization.role": [
"The selected authorization.role is invalid."
],
"users.0.email": [
"The users.0.email field is required."
],
"users.2.email": [
"The users.2.email must be a valid email address."
]
}
}
It would seem obvious for me to have this built-in natively, but I can't find a way to return the exact rule that was broken. For example:
$request->validate([
'name' => 'required'
]);
Then the returned error object should contain name.required, or something to know on the frontend which rule was broken. Now you can only get a localized message, and the 'name' key, and you have no idea which rule was broken. Doesn't Laravel have a way to return the broken rule, like name.required, name.unique, etc...
Thanks.