jeudi 26 novembre 2015

laravel 5.1 auth.login event triggered twice

Im building my app with laravel, and i create logger that log user login to mysql database, i used built in event auth.login, and then this is my code in class EventServiceProvider

This is my EventServiceProvider.php

protected $listen = [
    'App\Events\UserFailedLoggedInEvent' => [
        'App\Listeners\UserFailedLogginLogger',
    ],

];

/**
 * Register any other events for your application.
 *
 * @param  \Illuminate\Contracts\Events\Dispatcher  $events
 * @return void
 */
public function boot(DispatcherContract $events)
{
    parent::boot($events);

    $events->listen('votee.*', function($user, $voteable, $counter){
        $voteable->vote_down = $counter->down;
        $voteable->vote_up = $counter->up;
        $voteable->save();
    });

    $events->listen('mural.comment.add', function($comment, $content, $author, $room){
        $content->increment('comment');
    });

    $events->listen('mural.comment.remove', function($comment, $user){
        $comment->commentable->decrement('comment');
    });

    $events->listen('auth.logout', 'App\Listeners\UserLogoutLogger@handle');

    $events->listen('auth.login', 'App\Listeners\UserLoginLogger@handle');

}

}

And this is my App\Listeners\UserLoginLogger, i use spatie/activitylog

public function handle()
{
    Activity::log("Logged In");
}

but it will save to the database two login activity.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1YwSU3i
via IFTTT

Aucun commentaire:

Enregistrer un commentaire