简体   繁体   English

Laravel中的auth.register事件

[英]auth.register Event in Laravel

I am currently trying to add events for when a user registers in Laravel 5.1. 我目前正在尝试为用户在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 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. 我在Laravel网站上读到,您可以根据需要拥有任意数量的事件处理程序,因此真的不确定为什么不被触发。

Here is my listen events stored in EventServiceProvider: 这是我存储在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: 这是我从工匠的make命令构建的事件处理程序:

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 composer dumpautoload composer dump-autoload php artisan清除编译的php artisan优化php artisan缓存: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. 基本上,没有auth.register事件。 When you register a new user the auth.login event gets called for both registration and login. 当您注册新用户时,将同时注册和登录调用auth.login事件。

The website says: 该网站说:

When the attempt method is called, the auth.attempt event will be fired. 调用try方法时,将触发auth.attempt事件。 If the authentication attempt is successful and the user is logged in, the auth.login event will be fired as well. 如果身份验证尝试成功并且用户已登录,则还将触发auth.login事件。

This indicates that even when a user registers the auth.login event is called. 这表明即使在用户注册时,也会调用auth.login事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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