Skip to content

Conversation

@mosabbirrakib
Copy link

Problem:
When replace() or merge() methods are called in passedValidation(), the changes were not reflected in the validated() method because the validator instance held a copy of the original data.

Root Cause:
The validation flow in ValidatesWhenResolvedTrait::validateResolved() creates the validator instance before calling passedValidation(). When passedValidation() modifies the request data using replace() or merge(), the validator still has the old data, so validated() returns the original data instead of the modified data.

Solution:
After passedValidation() is called, sync the validator's data with the current request data using setData(). This ensures that any modifications made to the request data in passedValidation() are properly reflected in validated().

Changes:

  • Modified ValidatesWhenResolvedTrait::validateResolved() to sync validator data after passedValidation()
  • Added a test case to verify the fix works correctly
  • The fix is backward compatible and only affects cases where data is modified in passedValidation()

Testing:

  • Added testPassedValidationDataIsReflectedInValidatedMethod() test case
  • Existing tests continue to pass
  • The fix uses the existing validationData() method to get current data and setData() to update the validator

Fixes: #57659

When replace() or merge() methods are called in passedValidation(),
the changes were not reflected in the validated() method because
the validator instance held a copy of the original data.

This fix syncs the validator's data with the current request data
after passedValidation() is called, ensuring that any modifications
made to the request data are properly reflected in validated().

Fixes laravel#57659
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@mosabbirrakib
Copy link
Author

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Thanks for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants