Laravel 5: Events – Creating, Registering Events and Listeners

Scheduler: Events – Creating, Registering Events and Listeners


Events and listeners.

Note:
Eloquent has its own eventing system – see: here.

We have two ways to create/register event.

WAY 1: Using event:generate.
step 1: register event and its listeners with EventsServiceProvider:

We use protected method $listen, to register events and associated listeners.

step 2: run Artisan command to create files (and categories, if still not there)
Note:
Using this method, you will also create all events and listeners defined in method $listen, that are not created yet.

Note:
Above method will not generate subscribers.
You have to create it by hand and place it in Listeners directory, or you can put them in separate Subscribers directory.

 

WAY 2: Using separate Artisan commands for event and listener.
step 1: register event and its listeners with EventsServiceProvider:

This step is the same as above, where we used event:generate.

step 2: create event file

step 3: create listener file

step 4: create subscriber file

More in the next article.