maize-tech/laravel-email-domain-rule
Composer 安装命令:
composer require maize-tech/laravel-email-domain-rule
包简介
Laravel Email Domain Rule
README 文档
README
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
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
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
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
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
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
maize-tech/laravel-email-domain-rule 适用场景与选型建议
maize-tech/laravel-email-domain-rule 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.98k 次下载、GitHub Stars 达 61, 最近一次更新时间为 2021 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「laravel」 「domain」 「rule」 「maize-tech」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maize-tech/laravel-email-domain-rule 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maize-tech/laravel-email-domain-rule 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maize-tech/laravel-email-domain-rule 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Build a domain-oriented application on Laravel Framework
Command bus implementation: Commands and domain events
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
A module manager for Zend Framework which can be used to create configs per domain.
DDD auth basic class
统计信息
- 总下载量: 1.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 61
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-12