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

[Feature request] Upgrade ValidatorInterface::RULE_* #15

Open
brazorf opened this issue Mar 31, 2016 · 1 comment
Open

[Feature request] Upgrade ValidatorInterface::RULE_* #15

brazorf opened this issue Mar 31, 2016 · 1 comment

Comments

@brazorf
Copy link

brazorf commented Mar 31, 2016

It's nice to have separate create and update use cases, but i was thinking it would be way better to add the possibility to customize them.

To give you an example, think about a User model like this

username: string
password: string
email: string
age: int
phone: string

On certain use cases (i.e. change password) you would only want to validate username and password fields. On the other hand, you would validate email, age, phone when the user is updating his own profile. Each use case will have probably the same syntax rule, but may differ on the required rule.

So what about something like this:

protected $rules = [
        'create' => [
           // rules
        ],
        'update' => [
           // rules
        ],
        'change password' => [
          // only username and password rules
        ]
   ];

I'd like to hear your thoughts about this.

@brazorf brazorf changed the title [Feature request [Feature request] Upgrade ValidatorInterface::RULE_* Mar 31, 2016
@hugofabricio
Copy link

I use:

$this->validator->with($data)->passesOrFail('change_password');

protected $rules = [
        'create' => [
           // rules
        ],
        'update' => [
           // rules
        ],
        'change_password' => [
          // only username and password rules
        ]
   ];

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

No branches or pull requests

2 participants