There’s a hidden API endpoint you can use to validate if a provided Gmail address exists or is made up.

There’s a hidden API endpoint you can use to validate if a provided Gmail address exists or is made up.

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class ValidGmailAddress implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $response = Http::post('https://accounts.google.com/InputValidator?resource=signup&service=mail', ['input01' => [
            'Input' => 'GmailAddress', 'GmailAddress' => Str::before($value, '@gmail.com'), 'FirstName' => '', 'LastName' => ''
	], 'Locale' => 'en'])->json();
      
        return data_get($response, 'input01.ErrorMessage') == 'That username is taken. Try another.';
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The provided :attribute is not a valid Gmail address.';
    }
}