'How to check if email exists only when the email is verified in Laravel?

In Laravel 8 I have this validation in RegisterRequest:

public function rules()
{
    return [
        'name' =>'required|max:255',
        'email' =>'required|email|max:255|unique:users,email',
        'mobile' =>'required|digits:11|unique:users,mobile',
        'password' =>'required|confirmed|min:8|max:255'
    ];
}

The problem is that maybe the user entered the wrong email or maybe they entered someone else's email. I want to check if email exists only when the email is verified. How to do that?



Solution 1:[1]

Rule::unique('users','email')->where('email_verified_at')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 elmahdi bouzouggar