feat: expose prepared FormRequest data during validation failure#10259
Open
memleakd wants to merge 1 commit into
Open
feat: expose prepared FormRequest data during validation failure#10259memleakd wants to merge 1 commit into
FormRequest data during validation failure#10259memleakd wants to merge 1 commit into
Conversation
- Store prepared validation data before running FormRequest validation - Allow failedValidation() overrides to reuse the exact prepared payload - Avoid calling prepareForValidation() a second time in custom failure responses - Document normalized old-input handling Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
FormRequest data during validation failure
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.
Description
This PR proposes making the prepared FormRequest payload available while handling validation failure.
When a FormRequest normalizes input in
prepareForValidation(), that prepared data is what the validator actually checks. But if validation fails,failedValidation()did not have a clean way to access that same payload. The user guide example for flashing normalized old input had to callprepareForValidation($this->validationData())a second time just to rebuild it, which felt a bit off.This PR stores the prepared validation data when the FormRequest is resolved, and exposes it to subclasses with
getPreparedValidationData(). That gives customfailedValidation()implementations access to the exact payload that was passed to validation, without running preparation twice.The main use case is small and practical: if a request trims or canonicalizes visible form fields, a custom failure response can flash those prepared values back to the form instead of flashing raw submitted input.
This does not change the default validation failure response. Also, the prepared payload is still not trusted data; successful requests should continue using
getValidated()orgetValidatedInput().Checklist: