laravel check email is valid code example

Example 1: email validation in laravel

'email' => 'required|email|unique:users,email',
//@sujay

Example 2: email validation in laravel

'user.email' => 'required|email|unique:users,email,'.$user->id,
//@sujay

Example 3: laravel check if email is real

<?php
$email = "[email protected]";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}
?>

Example 4: email validation in laravel

$validator = Validator::make($request->all(), []);

 $validator->sometimes('email', 'unique:users,email', function ($input) {
            return $input->email !== Auth::user()->email;
        });
//@sujay