Repository navigation
Report nested validation errors under their path - #4
Merged
Merged
Conversation
A nested struct validated its own payload, so an invalid field in the second item of `details` failed as `label` instead of `details.1.label`. Clients could not tell which item was wrong. Nested structs are now hydrated through a generated `hydrateNested()`, which re-keys their errors under the field path and list index. Each level adds its own segment, so deeper nesting composes. The exception is rebuilt on a plain Validator, not through ValidationException::withMessages(), because that needs Laravel's facades and generated objects also run without them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The array rule also accepts maps, so a nested struct list may arrive with string keys. Typing the index as int made that a TypeError under strict types instead of a validation error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A nested struct validates its own payload, so its errors came back keyed by the nested field alone: an invalid
labelin the second item ofdetailsfailed aslabel, notdetails.1.label. A client can't tell which item was wrong.Generated structs with nested struct fields now hydrate them through a private
hydrateNested(), which re-keys the nestedValidationExceptionunder the field path and list index. Every level adds its own segment, so deeper nesting composes (nested_addresses.0.1.city).Validatorwith the original translator, not withValidationException::withMessages(), which needs Laravel's facades. Generated objects also run without Laravel, and the integration test covers that.