Created
May 19, 2020 01:32
-
-
Save owenconti/8fc1a6afe2602d52710021001ad06a92 to your computer and use it in GitHub Desktop.
How to handle multiple events with a single listener in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class EventServiceProvider extends ServiceProvider | |
| { | |
| /** | |
| * The event listener mappings for the application. | |
| * | |
| * @var array | |
| */ | |
| protected $listen = [ | |
| LoginEvent::class => [ | |
| HandleLoginListener::class | |
| ], | |
| ]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App\Events\NotifiableEvent.php | |
| <?php | |
| namespace App\Events; | |
| interface NotifiableEvent | |
| { | |
| /** | |
| * Returns the display name of the event. | |
| * | |
| * @return string | |
| */ | |
| public function getEventName(): string; | |
| /** | |
| * Returns the description of the event. | |
| * | |
| * @return string | |
| */ | |
| public function getEventDescription(): string; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // App\Events\CreatedApplicationMember.php | |
| <?php | |
| namespace App\Events; | |
| class CreatedApplicationMember implements NotifiableEvent | |
| { | |
| public function getEventName(): string | |
| { | |
| return 'Created Application Member'; | |
| } | |
| public function getEventDescription(): string | |
| { | |
| return 'Fired whenever a new Application Member is added to your Application.'; | |
| } | |
| // constructor and stuff goes here... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class EventServiceProvider extends ServiceProvider | |
| { | |
| /** | |
| * The event listener mappings for the application. | |
| * | |
| * @var array | |
| */ | |
| protected $listen = [ | |
| NotifiableEvent::class => [ | |
| SendEventNotification::class | |
| ], | |
| ]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment