lundi 4 juillet 2016

Why is Laravel event firing handle method twice?

Why my event listener's handle method firing twice?

I registered my event and listener on EventServiceProvider.php

protected $listen = [
        UserSignedUp::class => [
            SendConfirmationEmail::class
        ]
    ];

There's my event's constructor UserSignedUp.php (Event)

public function __construct(User $user)
    {
        $this->user = $user;
    }

There's my listener's handle method SendConfirmationEmail.php (Listener)

public function handle(UserSignedUp $event)
    {
        $user = $event->user;

        \Log::info($user->email);

        Mail::send('emails.signup.confirmation', ['email' => $user->email], function ($mail) use ($user) {
            $mail->to($user->email, $user->name)->subject('Subject line');
        });
    }

This is how I am firing the event in controller:

public function storeLogin()
{
    // Logic to store user
    Event::fire(new App\Events\UserSignedUp($user));

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire