I have set up an event that should run whenever a user registers successfully. The event runs but the listener handler is never triggered.
Any one know what I've done wrong here? I'm using Laravel 5.5 on a local development server (wamp).
It's not even getting to the listener's handle()
function, I put a dump in there to test.
Below is my code:
Event:
class UserRegisteredEmail extends Event {
use InteractsWithSockets, SerializesModels;
public $user;
public $password;
public function __construct($user, $password)
{
$this->user = $user;
$this->password = $password;
}
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
Event Listener:
class UserRegisteredEmailListener {
public function __construct()
{
}
public function handle(UserRegisteredEmail $event)
{
Notification::send($event->user, new NewAccountEmail($event->password));
}
}
EventServiceProvider:
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
'App\Events\Event' => [
'App\Listeners\EventListener',
'App\Listeners\UserRegisteredEmailListener'
],
];
public function boot()
{
parent::boot();
//
}
}
UserService
where the event is dispatched:
DB::transaction(function () use ($user, $password, $role, $sendEmail) {
$this->userMeta->firstOrCreate([
'user_id' => $user->id
]);
if ($sendEmail) {
event(new UserRegisteredEmail($user, $password));
}
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire