我已经 在我的 Laravel 应用程序中实现了电子邮件验证。默认情况下,当用户注册时,会向用户发送验证邮件。但是,我想要的是向我的邮箱发送一封验证邮件,也就是选择收件人,以便站点管理员(在本例中为我)可以批准用户注册。
有没有办法做到这一点?如何?
为此,我不推荐 Laravel 附带的默认用户电子邮件验证,即use Illuminate\Contracts\Auth\MustVerifyEmail;
如果您想要这样做,那么用户必须得到管理员的批准,我会设置一个辅助字段,它不是email_verified_at
.
修改您的用户迁移database/migrations/*********_create_users_table.php
并添加一个布尔字段。
...
class CreateUsersTable extends Migration
{
...
public function up()
{
Schema::create('users', function (Blueprint $table) {
...
$table->boolean('approved');
...
});
}
...
}
然后你可以创建一个新的中间件来检查用户是否被批准。
为了触发电子邮件,我将添加当用户在侦听数组中注册时触发的事件app/Providers/EventServiceProvider.php
...
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
/* add some notification here that sends you an email */
],
];
...
抱歉,这个答案并不详细,但它会让你继续前进。