V
V
Vasyl Fomin2016-11-28 17:40:05
Laravel
Vasyl Fomin, 2016-11-28 17:40:05

How to use standard Laravel 5.3 events?

Modifying my previous question a bit : Need to track user login (authorization) events in Laravel 5.3. I already know that there is and you can use the standard 'auth.login' login event, and write a handler for this event - as I understand it, the Listener.
I do it as follows:
1) In app/Providers/EventServiceProvider.php I add

protected $listen = [ 'auth.login' => ['App\Listeners\UserEventListener']];

2) In the App\Listeners\UserEventListener listener, in the handle method, I write the code:
public function handle()
    {
        Log::info("Пользователь вошел!");
    }

As a result, nothing is written to the log!
If I create my own event (UserVisitedEvent) and write in EventServiceProvider.php
protected $listen = [ 'App\Events\UserVisitedEvent' => ['App\Listeners\UserEventListener']];

and then I call
Event::fire(new UserVisitedEvent());
it, it works like this, it writes to the log "The user is logged in!". I studied the documentation, but found little information
about built- in events In general, how to use built-in events?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2016-11-28
@fomvasss

And you try to read the official documentation -  https://laravel.com/docs/5.3/authentication#events , and not any junk.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question