andersao / laravel-validator

Laravel Validation Service
http://andersao.github.io/laravel-validator
MIT License
411 stars 82 forks source link

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

Open brazorf opened 8 years ago

brazorf commented 8 years ago

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.

hugofabricio commented 8 years ago

I use:

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

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