laravel-validator
laravel-validator copied to clipboard
[Feature request] Upgrade ValidatorInterface::RULE_*
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.
I use:
$this->validator->with($data)->passesOrFail('change_password');
protected $rules = [
'create' => [
// rules
],
'update' => [
// rules
],
'change_password' => [
// only username and password rules
]
];