Skip to content

Describe exists/unique rule objects kept by the validator (Laravel 13.43+) - #1093

Open
SamuelMwangiW wants to merge 2 commits into
knuckleswtf:v5from
SamuelMwangiW:fix/exists-unique-rule-objects
Open

SamuelMwangiW wants to merge 2 commits into
knuckleswtf:v5from
SamuelMwangiW:fix/exists-unique-rule-objects

Conversation

@SamuelMwangiW

Copy link
Copy Markdown

I observed an unexpected diff after upgrading Laravel where the description was dropped.

After a bit of digging, I found out out laravel/framework v13.43.0 shipped a change where ValidationRuleParser::prepareRule() no longer casts an Exists or Unique rule to a string when it has a where() clause:

// v13.42.0
($rule instanceof Exists && $rule->queryCallbacks()) ||
// v13.43.0
($rule instanceof Exists && $rule->queryConditions()) ||

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. Plain exists:table,column strings, and Rule::exists() without a where(), are unaffected.

This PR casts Exists and Unique rule objects back to their string form in normaliseRules(). 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.

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.
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.

1 participant