In Laravel Validation if you mark some request parameters to be having validation other than required i.e. email, numeric, digits, url etc. Even if the field is not set as required Laravel will complain about the validation rules even if the field is marked as not requied.

For example if you have validation of a field which needs to be an email. Here is how you would write the validation rule


'user_email' => 'email'

If the field is left empty by the user Laravel will complain about the invalid email since the null / empty value is not an valid email.

To fix this you need to tell Laravel that the field can be nullable and if filled should be an valid email.


'user_email' => 'nullable|email'

This way the field can be left empty and if filled the Laravel will kick-in the email validation.

Comments