PHP code example of aliziodev / laravel-gmail-unique

1. Go to this page and download the library: Download aliziodev/laravel-gmail-unique library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aliziodev / laravel-gmail-unique example snippets


return [
    // Email domains to normalize (default: gmail.com and googlemail.com)
    'domains' => ['gmail.com', 'googlemail.com'],

    // The column name used for email in your database (default: email)
    'email_column' => 'email',

    // Error message for duplicate Gmail addresses
    'error_message' => 'This email is already taken (normalized Gmail detected).'
];



namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Aliziodev\GmailUnique\Traits\HasNormalizedEmail;

class User extends Authenticatable
{
    use HasNormalizedEmail;

    // ... rest of your model
}



namespace App\Http\Controllers;

use Aliziodev\GmailUnique\Facades\GmailUnique;
use App\Models\User;

class UserController extends Controller
{
    public function checkEmail($email)
    {
        // Normalize an email address
        $normalized = GmailUnique::normalize($email);

        // Check if a normalized version already exists
        $isDuplicate = GmailUnique::isDuplicate($email, User::class, $excludeId = null);

        return [
            'original' => $email,
            'normalized' => $normalized,
            'isDuplicate' => $isDuplicate
        ];
    }
}



namespace App\Http\Controllers;

use Aliziodev\GmailUnique\Services\GmailUniqueService;
use App\Models\User;

class UserController extends Controller
{
    protected $gmailService;

    public function __construct(GmailUniqueService $gmailService)
    {
        $this->gmailService = $gmailService;
    }

    public function checkEmail($email)
    {
        // Normalize an email address
        $normalized = $this->gmailService->normalize($email);

        // Check if a normalized version already exists
        $isDuplicate = $this->gmailService->isDuplicate($email, User::class, $excludeId = null);

        return [
            'original' => $email,
            'normalized' => $normalized,
            'isDuplicate' => $isDuplicate
        ];
    }
}

use Aliziodev\GmailUnique\Services\GmailUniqueService;
use App\Models\User;

// In a form request or controller
$validated = $request->validate([
            'name' => ['$value, $fail) {
                    $gmailService = app(GmailUniqueService::class);
                    if ($gmailService->isDuplicate($value, User::class)) {
                         $fail('This email address is already taken.');
                    }
                }
            ],
            'password' => ['
bash
php artisan gmail-unique:install