Validate optional fields in Laravel

At times in your laravel validation, you may want input field to be validated only if the user filled in the field and you may want to skip the validation if there is field is left blank. This can be useful with email fields, numeric / integer fields etc.

You can make use of nullable validation to only validate if user provided an value for the field.


'age' => 'nullable|integer',
'email' => 'nullable|email'

In the example above, if validation will return an error if user provided a non integer value for age and invalid email in the email field. If the fields are left blank no error will be returned.

Site Footer