Skip to content
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

[8.x] Make Validator::parseNamedParameters public #35183

Merged
merged 1 commit into from
Nov 11, 2020
Merged

[8.x] Make Validator::parseNamedParameters public #35183

merged 1 commit into from
Nov 11, 2020

Conversation

ragulka
Copy link
Contributor

@ragulka ragulka commented Nov 11, 2020

This change will allow custom validation rules having access to the validator to parse named parameters.

Consider a custom validation rule using a closure or extension:

Validator::extend('custom_rule', function($attribute, $value, $parameters, $validator) {
  // the parameters are something like ['country=US', 'level=pro'],
  // but we want ['country' => 'US', 'level' => 'pro'] instead
  dd($parameters);
  // this will give us what we want (but currently it fails, because the method is protected)
  dd($validator->parseNamedParameters($parameters));
});

Validator::make([
  'some_field' => 'custom_rule:country=US,level=pro'
], $data);

There are no breaking changes, it simply exposes a helpful method to custom validation rules.

This change will allow custom validation rules having access to the validator to parse named parameters.
@ragulka ragulka changed the title Make Validator::parseNamedParameters public [8.x] Make Validator::parseNamedParameters public Nov 11, 2020
@taylorotwell taylorotwell merged commit c26bbea into laravel:8.x Nov 11, 2020
@driesvints
Copy link
Member

Just want to note that this is a breaking change.

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.

None yet

3 participants