

Then you have to put bellow code on app/Listeners/SendMailFired.php. In this event listener we have to handle event code, i mean code of mail sending, Before this file you have to check your mail configration, If you did not set then you can set this way : How to set gmail configration for mail in Laravel 8?. Php artisan make:listener SendMailFired -event="SendMail" So create event listener using bellow command. Now, I need to create event listener for "SendMail" event. If we had implemented the examples discussed so far in this article using the event subscriber, it might look like this.

Return new PrivateChannel('channel-name') * Get the channels the event should broadcast on. As we continue to work on the application we may move more towards Events or away from it if we find an alternative, but for now it’s meeting our needs.App/Events/SendMail.php and put bellow code in that file. We chose to do it this way because the Events package was already there and had things like priority and data passing capabilities that we would need and there were few shortcomings from a developer perspective to implementing the system this way. The other issue, as noted above, is that there is likely a better way to do some of this. This could be as simple as only registering config listeners when “config” exists in the current route. The basic implementation isn’t very taxing, but as we continue to develop we will be looking for ways to avoid firing events if there won’t be a listener for that request. The one downfall to this system may end up being our overhead. The next step I took was to start putting these into practice with a few simple examples that I found very useful.Įvent :: listen ( 'user.logout', function ( $user )

Keep in mind this is priority not order so the higher the number, the earlier it is triggered.Įverything above is more or less covered in the documentation and with a basic knowledge of how Events work. Simply pass a third parameter after the closure with a numeric value (ie: 5).
