[bug] add failing tests for array/collection nested data #1117
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.
✏️ Describe the bug
Validation rules referencing other field within a nested data inside an array or Illuminate\Support\Collection do not work. The validation rules only work when using the deprecated
DataCollection.The docs mention that for nesting a collection of data,
DataCollectionis deprecated and either a simple array and phpdoc, orIlluminate\Support\Collectionshould be used, instead.In fact, the docs only show an example of using phpdoc annotation for a collection of data objects in the validation section.
However, it appears that some validation rules simply do not work when using these preferred method. I haven't tested everything, but it seems that rules referencing other fields on the nested Data object do not work.
I'm not sure why, but my hunch is that the validation path is not correctly set when the rules are generated.
↪️ To Reproduce
See the failing tests in the PR.
✅ Expected behavior
Rules referencing other fields on a nested data object contained within an array or Collection on the parent data object work as expected.
🖥️ Versions
Laravel: 12
Laravel Data: 4.18.0
PHP: 8.4