The Laravel Event feature is pretty useful, just like Trigger in DBMS;

I’ve tried to register more than 1 Listener to an event.

E.g. in app/Providers/EventServiceProvider.php

1
2
3
4
5
6
7
8
9
<?php
...

protected $listen = [
AccountCreated::class => [
SendActivationEmail::class,
SendSMS::class,
],
];

Example above shows that once account is created, system will send the activation email automatically, followed by send SMS.

I’ve encounter the problem that the 2nd listener is not triggered.

Why?

The reason behind is, there’s a return false; in SendActivationEmail::handler. E.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
...
class CreateAnnouncementOfferUpdated
{
...

public function handle(AccountCreated $event)
{
...

if ($event->account->is_fb_login) {
return false;
}

...
}
}

The return false; indicate that the rest of listeners will not be executed.

So what I did was, use return; instead of return false;. i.e.

1
2
3
if ($event->account->is_fb_login) {
return;
}