I'm trying to do some form validations in Laravel 5.8,
But even on the fields that don't have the required
rule, it throws error...
for example:
request()->validate([
'username' => ['required','alpha_num','max:40'],
'email' => ['email','max:100'],
]);
If I leave the email
field "empty" (it is not required) on the form it fails to submit and shows this error: The email must be a valid email address.
I don't understand, why is this happening? and what is the use of required
rule when this is the behavior of Laravel validation?
Coming from CodeIgniter community, this is confusing.
Should I also include nullable
rule in fields that can be empty?
nullable
. – lufc