简体   繁体   中英

auth.register Event in Laravel

I am currently trying to add events for when a user registers in Laravel 5.1. I have managed to add 2 event handlers that work perfectly, however when I build out another event using:

php artisan handler:event UserVotesAfterRegister

This does not get called, at all. I read on the Laravel website that you can have as many event handlers as you like so really not sure why this is not getting fired.

Here is my listen events stored in EventServiceProvider:

protected $listen = [
    'App\Events\SomeEvent' => [
        'App\Listeners\EventListener',
    ],
    'SocialiteProviders\Manager\SocialiteWasCalled' => [
        // add your listeners (aka providers) here
        'SocialiteProviders\Tumblr\TumblrExtendSocialite@handle'
    ],
    'auth.login' => [
        'App\Handlers\Events\UserVotesAfterLogin',
        'App\Handlers\Events\AddInteractionLog',
        'App\Handlers\Events\PageInteractionTracking',
    ],
    'auth.register' => [
        'App\Handlers\Events\UserVotesAfterRegister',
        'App\Handlers\Events\AddInteractionLog',
        'App\Handlers\Events\PageInteractionTracking',
    ],
    'auth.password' => [
        'App\Handlers\Events\AddInteractionLog',
        'App\Handlers\Events\PageInteractionTracking',
    ],
    'auth.logout' => [
        'App\Handlers\Events\AddInteractionLog',
    ],
];

And here is my event handler that was built from the artisan make command:

namespace App\Handlers\Events;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User;

class UserVotesAfterRegister
{
    /**
     * Create the event handler.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  Events  $event
     * @return void
     */
    public function handle()
    {
        //
        dd("DIE");
    }
}

Any help would be appreciated.

I have tried to clear all caches using:

composer dumpautoload composer dump-autoload php artisan clear-compiled php artisan optimize php artisan cache:clear

...but to no avail

namespace App\Handlers\Events;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User;

class UserVotesAfterRegister
{
/**
 * Create the event handler.
 *
 * @return void
 */
public function __construct()
{
    //
}

/**
 * Handle the event.
 *
 * @param  Events  $event
 * @return void
 */
public function handle(SomeEventHandler $event)
{
    // The $event is missing here. Please consider it first and try again.
    dd("DIE");
}
}

Right,

Think I have figured this out. Basically, there is no auth.register event. When you register a new user the auth.login event gets called for both registration and login.

The website says:

When the attempt method is called, the auth.attempt event will be fired. If the authentication attempt is successful and the user is logged in, the auth.login event will be fired as well.

This indicates that even when a user registers the auth.login event is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM