Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

laravel
php
communitycreator

How to make a field optional using the validation rule in Laravel

Chinweuba Elijah Azubuike

Overview

In this shot, you will learn how to create optional and validated fields submitted from your form. This rule is one of the Laravel validation rules that accepts empty fields and still validates them.

Note: If these fields are NOT NULLABLE on your database, this will throw errors. Therefore, the fields have to be NULLABLE in the database.

Usage

$request->validate([
'publish_at'=>'nullable|date',
]);

The above code uses the nullable Laravel rule.

The code passes validation even though the publish_at field is empty because of the nullable rule.

If the field is filled, it ensures that the field is a date value because it also has the date validation rule.

RELATED TAGS

laravel
php
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring