F
F
fiter2017-03-09 20:51:02
Laravel
fiter, 2017-03-09 20:51:02

How to make alpha_dash field optional in laravel?

Validates old and new password:

'old_password' => 'max:255|required_with:new_password|old_password',
'new_password' => 'max:255|required_with:old_password|min:6|alpha_dash',

If the user did not enter the old and new password, then the validation should pass without errors.
But the empty field New password produces validation errors on min:6 and alpha_dash
How can I get rid of these errors?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Afatar, 2017-03-10
@Afatar

You can add nullable. If the field is empty, then the rest of the validation will not pass.

'new_password' => 'nullable|max:255|required_with:old_password|min:6|alpha_dash'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question