dimanche 25 novembre 2018

Laravel Auth Registered Event doesn't seem to be firing when email verification is enabled

I have a simple auth registered event handler which looks like this:

<?php

namespace App\Listeners;

use App\AuditLog;
use Illuminate\Auth\Events\Registered as RegisteredEvent;

class AuthRegisteredEventHandler
{
    public function handle(RegisteredEvent $event)
    {
        if ($event->user) {
            $auditLog = new AuditLog;
            $auditLog->description = 'New account created.';
            $auditLog->save;
        }
    }
}

This is hooked up in the EventServiceProvider like this:

<?php

namespace App\Providers;

use App\Listeners\{ AuthRegisteredEventHandler, AuthLoginEventHandler };
use Illuminate\Auth\Events\{ Registered as RegisteredEvent, Login as LoginEvent};
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        RegisteredEvent::class => [
            SendEmailVerificationNotification::class,
            AuthRegisteredEventHandler::class,
        ],
        LoginEvent::class => [
            AuthLoginEventHandler::class,
        ],
    ];

I am using laravel's built in auth scaffold (php artisan make:auth) and registered an account and expected see a record in audit_logs table - but it's empty and no errors were thrown. I did get my email confirmation.

Any ideas what might be wrong? I am using php 7.1 and Laravel 5.7. Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire