feat: allow FormRequest validation failures to reach controllers#10300
Open
memleakd wants to merge 2 commits into
Open
feat: allow FormRequest validation failures to reach controllers#10300memleakd wants to merge 2 commits into
FormRequest validation failures to reach controllers#10300memleakd wants to merge 2 commits into
Conversation
Let `FormRequest::failedValidation()` return `null` when an application wants the controller action to render the invalid response. - Keep existing ResponseInterface short-circuit behavior - Preserve authorization failures as immediate responses - Document controller-handled validation failures Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.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.
Description
FormRequestcurrently assume that a validation failure owns the response: either the default redirect/JSON response, or whatever the request returns fromfailedValidation().That works well for many requests, but it is too rigid for server-rendered forms where the invalid response belongs to the controller action. Sometimes the controller already has the route context, loaded resource, page surface, or view composition needed to render the failed form correctly.
This PR keeps the default behavior unchanged. If
failedValidation()returns aResponseInterface, the framework still short-circuits and sends it immediately.The only new path is that
failedValidation()may now returnnull. In that case, the resolvedFormRequestis injected into the controller, and the controller can handle the failed validation itself.This avoids adding a second flag method or framework-owned error state. The request class can store whatever state the application needs, and the framework only needs to understand one thing: response means stop, null means continue.
Tests cover the default short-circuit behavior, the new controller-handled path, prepared validation data, and authorization still stopping before validation.
Checklist: