-
Notifications
You must be signed in to change notification settings - Fork 33
Registering Listeners
Denis Duliçi edited this page Nov 20, 2019
·
3 revisions
Your module may require event listeners. You can create these classes manually, or with the following helpers:
php artisan module:make-listener NotifyAdminOfNewLogin my-blogOnce those are created you need to register them in Laravel. This can be done in 2 ways:
You can register the event using the Laravel method called listen that is available in the Main service provider class.
$this->app['events']->listen(Illuminate\Auth\Events\Login::class, NotifyAdminOfNewLogin::class);Create a new class called Event in the Modules/MyBlog/Providers folder that extends the EventServiceProvider of Laravel. This class will look like this:
<?php
namespace Modules\MyBlog\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Modules\MyBlog\Listeners\NotifyAdminOfNewLogin;
class Event extends ServiceProvider
{
protected $listen = [
Illuminate\Auth\Events\Login::class => [
NotifyAdminOfNewLogin::class,
],
];
}The last thing to do is to add it to your module.json file and clear cache:
...
"providers": [
"Modules\\MyBlog\\Providers\\Main",
"Modules\\MyBlog\\Providers\\Event"
],
...