注册时可以登录, 写了注册时触发发送激活邮件,但是没有效果。

代码如下
RegisteredListener.php
<?php

namespace App\Listeners;

use App\Notifications\EmailVerificationNotification;
use Illuminate\Auth\Events\Registered;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

// implements ShouldQueue 让这个监听器异步执行
class RegisteredListener implements ShouldQueue
{
// 当事件被触发时,对应该事件的监听器的 handle() 方法就会被调用
public function handle(Registered $event)
{
// 获取到刚刚注册的用户
$user = $event->user;
// 调用 notify 发送通知
$user->notify(new EmailVerificationNotification());
}
}

EventServiceProvider.php
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use App\Listeners\RegisteredListener;
use Illuminate\Auth\Events\Registered;

class EventServiceProvider extends ServiceProvider
{
/**

  • The event listener mappings for the application.
  • @var array
    */
    protected $listen = [
    'App\Events\Event' => [
    RegisteredListener::class,
    ],
    ];

    /**

  • Register any events for your application.
  • @return void
    */
    public function boot()
    {
    parent::boot();

    //

    }
    }

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
leo
最佳答案

EventServiceProvider 写错了

5年前 评论
讨论数量: 2
leo

EventServiceProvider 写错了

5年前 评论

@leo 好的,谢谢。刚刚也排查到了,应该改为
protected $listen = [
Registered::class => [
RegisteredListener::class,
],
];

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!