PHPackages                             h-farm/laravel-email-domain-rule - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. h-farm/laravel-email-domain-rule

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

h-farm/laravel-email-domain-rule
================================

Laravel Email Domain Rule

3.2.0(2y ago)612849[5 PRs](https://github.com/maize-tech/laravel-email-domain-rule/pulls)MITPHPPHP ^8.0CI passing

Since Jun 16Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/maize-tech/laravel-email-domain-rule)[ Packagist](https://packagist.org/packages/h-farm/laravel-email-domain-rule)[ Docs](https://github.com/maize-tech/laravel-email-domain-rule)[ GitHub Sponsors](https://github.com/maize-tech)[ RSS](/packages/h-farm-laravel-email-domain-rule/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (9)Versions (10)Used By (0)

   ![Social Card of Laravel Email Domain Rule](/art/socialcard-light.png)

Laravel Email Domain Rule
=========================

[](#laravel-email-domain-rule)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d83900f56c5c3d85c0cded753c36abee17e136d1df4255450911d9034773aadf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61697a652d746563682f6c61726176656c2d656d61696c2d646f6d61696e2d72756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-email-domain-rule)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a2ca5bb15989f4703b84fb5f0cdcb60cf1f8ff13ae60b437dade7a670e4421a4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d656d61696c2d646f6d61696e2d72756c652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-email-domain-rule/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/56e848f64a6ec2ff52cd94292e2b3f66a9a2db80d05d03576ede19799d439819/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d656d61696c2d646f6d61696e2d72756c652f7068702d63732d66697865722e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-email-domain-rule/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/46c1e33385e509e79f83a88ba13c02b867a2813d8974333112f686f8d8ad18eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61697a652d746563682f6c61726176656c2d656d61696c2d646f6d61696e2d72756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-email-domain-rule)

This package allows to define a subset of allowed email domains and validate any user registration form with a custom rule.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require maize-tech/laravel-email-domain-rule
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Maize\EmailDomainRule\EmailDomainRuleServiceProvider" --tag="email-domain-rule-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Maize\EmailDomainRule\EmailDomainRuleServiceProvider" --tag="email-domain-rule-config"
```

This is the content of the published config file:

```
return [

    /*
    |--------------------------------------------------------------------------
    | Email Domain model
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the email domain model.
    |
    */

    'email_domain_model' => Maize\EmailDomainRule\Models\EmailDomain::class,

    /*
    |--------------------------------------------------------------------------
    | Email Domain wildcard
    |--------------------------------------------------------------------------
    |
    | Here you may specify the character used as wildcard for all email domains.
    |
    */

    'email_domain_wildcard' => '*',

    /*
    |--------------------------------------------------------------------------
    | Validation message
    |--------------------------------------------------------------------------
    |
    | Here you may specify the message thrown if the validation rule fails.
    |
    */

    'validation_message' => 'The selected :attribute does not have a valid domain.',
];
```

Usage
-----

[](#usage)

### Basic

[](#basic)

To use the package, run the migration and fill in the table with a list of accepted email domains for your application.

You can then just add the custom validation rule to validate, for example, a user registration form.

```
use Maize\EmailDomainRule\EmailDomainRule;
use Illuminate\Support\Facades\Validator;

$email = 'my-email@example.com';

Validator::make([
    'email' => $email,
], [
    'email' => [
        'string',
        'email',
        new EmailDomainRule,
    ],
])->validated();
```

That's all! Laravel will handle the rest by validating the input and throwing an error message if validation fails.

### Wildcard domains

[](#wildcard-domains)

If needed, you can optionally add wildcard domains to the `email_domains` database table: the custom rule will handle the rest.

The default wildcard character is an asterisk (`*`), but you can customize it within the `email_domain_wildcard` setting.

```
use Maize\EmailDomainRule\EmailDomainRule;
use Maize\EmailDomainRule\Models\EmailDomain;
use Illuminate\Support\Facades\Validator;

EmailDomain::create(['domain' => '*.example.com']);

Validator::make([
    'email' => 'info@example.com',
], [
    'email' => ['string', 'email', new EmailDomainRule],
])->fails(); // returns true as the given domain is not in the list

Validator::make([
    'email' => 'info@subdomain.example.com',
], [
    'email' => ['string', 'email', new EmailDomainRule],
])->fails(); // returns false as the given domain matches the wildcard domain
```

### Model customization

[](#model-customization)

You can also override the default `EmailDomain` model to add any additional field by changing the `email_domain_model` setting.

This can be useful when working with a multi-tenancy scenario in a single database system: in this case you can just add a `tenant_id` column to the migration and model classes, and apply a global scope to the custom model.

```
use Maize\EmailDomainRule\EmailDomainRule as BaseEmailDomain;
use Illuminate\Database\Eloquent\Builder;

class EmailDomain extends BaseEmailDomain
{
    protected $fillable = [
        'domain',
        'tenant_id',
    ];

    protected static function booted()
    {
        static::addGlobalScope('tenantAware', function (Builder $builder) {
            $builder->where('tenant_id', auth()->user()->tenant_id);
        });
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/maize-tech/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](https://github.com/maize-tech/.github/security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Riccardo Dalla Via](https://github.com/riccardodallavia)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance52

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~255 days

Total

5

Last Release

767d ago

Major Versions

1.0.0 → 2.0.02021-10-12

2.0.0 → 3.0.02022-02-16

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

3.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0412f3202d0534dbd7d714e855b19475a6790f09bc3c83638ef7c6d41d220ad?d=identicon)[h-farm](/maintainers/h-farm)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (22 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (16 commits)")[![enricodelazzari](https://avatars.githubusercontent.com/u/10452445?v=4)](https://github.com/enricodelazzari "enricodelazzari (7 commits)")[![frestifo](https://avatars.githubusercontent.com/u/138138732?v=4)](https://github.com/frestifo "frestifo (1 commits)")[![riccardodallavia](https://avatars.githubusercontent.com/u/1372062?v=4)](https://github.com/riccardodallavia "riccardodallavia (1 commits)")

---

Tags

emaillaravelphpregistrationrulevalidationlaravelemailruledomainmaize-tech

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/h-farm-laravel-email-domain-rule/health.svg)

```
[![Health](https://phpackages.com/badges/h-farm-laravel-email-domain-rule/health.svg)](https://phpackages.com/packages/h-farm-laravel-email-domain-rule)
```

###  Alternatives

[maize-tech/laravel-email-domain-rule

Laravel Email Domain Rule

611.9k](/packages/maize-tech-laravel-email-domain-rule)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[propaganistas/laravel-disposable-email

Disposable email validator

5762.6M6](/packages/propaganistas-laravel-disposable-email)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[maize-tech/laravel-magic-login

Laravel Magic Login

1808.1k](/packages/maize-tech-laravel-magic-login)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
