Repository navigation
Describe exists/unique rule objects kept by the validator (Laravel 13.43+) - #1093
Open
SamuelMwangiW wants to merge 2 commits into
Open
SamuelMwangiW wants to merge 2 commits into
SamuelMwangiW wants to merge 2 commits into
Conversation
Since laravel/framework v13.43.0, ValidationRuleParser::prepareRule() keeps an Exists or Unique rule that has a where() clause as an object, rather than casting it to its string form. Scribe only parses string rules, so such a field lost its "Must match an existing stored value." description. Cast these rules back to strings when normalising, which also describes rules with a using() callback, never cast to strings.
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.
I observed an unexpected diff after upgrading Laravel where the description was dropped.
After a bit of digging, I found out out
laravel/frameworkv13.43.0 shipped a change whereValidationRuleParser::prepareRule()no longer casts an Exists or Unique rule to a string when it has a where() clause:This was introduced in laravel/framework#62425
normaliseRules() gets its rules from Validator::make(...)->getRules(), so such a rule now arrives as an object. But getParametersFromValidationRules() only parses string rules, plus Rule/ValidationRule objects, which Exists and Unique are not. So a field like
Rule::exists('contacts', 'id')->where('user_id', $id)lost its "Must match an existing stored value." description after upgrading Laravel. Plainexists:table,columnstrings, andRule::exists()without awhere(), are unaffected.This PR casts
ExistsandUniquerule objects back to their string form innormaliseRules(). This maintains existing behavior. It also covers rules with a using() callback, which Laravel has always kept as objects and hence were never described.Backward compatibility
This change should be forward and backward compatible
Tests
I stand guided if the single test is sufficient.