-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Outsourcing validation rules to validationRules() method in FormRequest@createDefaultValidator() method breaks validation #50083
Comments
Heya, thanks for reporting. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up. laravel new bug-report --github="--public" Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
Hi @driesvints, thanks for the fast response! I followed your instructions reproduced the issue in this repository: https://github.com/lakkes-ra/bug-report. |
This is happening because the PR changed the order in which the rules and data are retrieved. While this is a breaking change, I don't think the merging of data is supposed to happen in the rules method. You should be using the See: https://laravel.com/docs/10.x/validation#preparing-input-for-validation |
@rojtjo that works, thanks for pointing out & thanks to @driesvints for fixing! |
Laravel Version
10.43
PHP Version
8.2.14
Database Driver & Version
Docker MySQL image mysql:8.0
Description
References #49860
This change breaks my custom FormRequest rules where I use the merge() function.
With Update 10.43 it returns validation errors "start date must be filled" and "end date must be filled". When I revert the changes made in FormRequest@createDefaultValidator(ValidationFactory $factory) in #49860, it works again.
It is kinda weird, since the problem only seems to be coming from outsourcing
$rules = method_exists($this, 'rules') ? $this->container->call([$this, 'rules']) : [];
into a method. It all works fine, if I do it inside thecreateDefaultValidator()
methodSteps To Reproduce
Create a custom FormRequest and use merge inside the rules() function like written above.
The text was updated successfully, but these errors were encountered: