LaravelPackages.net
Acme Inc.
Toggle sidebar
antriver/laravel-unique-email-validator

Laravel validation rule to check an email address is really unique.

10
0
1.0.0
About antriver/laravel-unique-email-validator

antriver/laravel-unique-email-validator is a Laravel package for laravel validation rule to check an email address is really unique.. It currently has 0 GitHub stars and 10 downloads on Packagist (latest version 1.0.0). Install it with composer require antriver/laravel-unique-email-validator. Discover more Laravel packages by antriver or browse all Laravel packages to compare alternatives.

Last updated

Laravel Unique Email Validator

This provides a Laravel validation rule that improves upon the built in 'unique' rule when preventing the same email address being used more than once.

Some email providers (Gmail) allow you to use + in the email address to create 'aliases'. For example if your email address is [email protected] you can also use:

and they all work. The normal 'unique' rule would allow these as they are all different. This rule sees these all as the same and will disallow using the same '[email protected]' account.

Some email providers (Gmail) also allow you to place periods anywhere before the @ sign in the email address and these will all work. For example if your email address is [email protected] you can also use:

Requirements

Your MySQL server must support the non-greedy regex operator. This has been tested with MySQL 8 and MariaDB 10.2 so those versions or newer should work.

Installation

composer require antriver/laravel-unique-email-validator

Usage

    $this->validate(
        $request,
        [
            // Check for other use of the same email address in the users.email column.
            'email' => [new \Antriver\LaravelUniqueEmailValidator\UniqueEmailRule('users', 'email')],
        ]
    );

Like the original unique rule you can specify certain rows should be excluded. This is useful when updating a user and that should not reject the user's existing registered email address:

    $this->validate(
        $request,
        [
            'email' => [new \Antriver\LaravelUniqueEmailValidator\UniqueEmailRule('users', 'email', ['id' => 123])],
            // Where 123 is the 'id' of the existing user.
        ]
    );

Star History Chart