laravel-validator icon indicating copy to clipboard operation
laravel-validator copied to clipboard

[Feature request] Upgrade ValidatorInterface::RULE_*

Open brazorf opened this issue 8 years ago • 1 comments

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 avatar Mar 31 '16 13:03 brazorf

I use:

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

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

hugofabricio avatar Apr 13 '16 16:04 hugofabricio