Laravel 7/6 Validation Email or Empty Example




Laravel 7/6  Validation Email or Empty Example

Hi Guys,

In this example,I will learn you how to use valid email or empty validation in can easy to use valid email validation in laravel.

In this example, i want to show you how to use email validation with optional field in laravel application. so if user does not want to add email then it's optional and if he enter something on text box then email validation will execute.

Here is a solution and i also give you full example with route and view file too.

Let's see bellow solution:

$validator = $request->validate([

'name' => 'required|nullable|string',

'email' => 'nullable|email',


Route : routes/web.php



Controller : app/Http/Controller/


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller


public function index()


return view('form');


public function store(Request $request)



$validator = $request->validate([

'name' => 'required|nullable|string',

'email' => 'nullable|email',


return redirect()->back();



View : resources/views/form.blade.php

<!DOCTYPE html>



<title>laravel validation email or empty</title>

<link rel="stylesheet" href="" integrity="sha256-L/W5Wfqfa0sdBNIKN9cG6QA5F2qx4qICmU2VgLruv9Y=" crossorigin="anonymous" />

<script src="" integrity="sha256-WqU1JavFxSAMcLP2WIOI+GB2zWmShMI82mTpLDcqFUg=" crossorigin="anonymous"></script>


<body style="background: skyblue">

<div class="container">

<div class="row">

<div class="col-md-6 offset-3">

<div class="card mt-5">

<div class="card-header bg-success">

<h3 class="text-white text-center"><strong>laravel validation email or empty</strong></h3>


<div class="card-body">

@if(count($errors) > 0)

@foreach($errors->all() as $error)

<div class="alert alert-danger">{{ $error }}</div>



<form action="{{ route('') }}" method="post">


<div class="form-group">

<label><b>Name :-</b></label>

<input type="text" name="name" class="form-control" value="{{ old('password') }}">


<div class="form-group">


<input type="text" name="email" class="form-control" value="{{ old('email') }}">


<div class="form-group text-center">

<button class="btn btn-success" type="submit">Save</button>










It will help you....

#Laravel 7


#Laravel 6