How to create events and event listeners in bagisto?

Updated 4 August 2022

Most Common requirement of a website is to perform an action whenever any task or some event occurs. In this article, we are going to see how to create events and event listeners in bagisto.

For example – Send an email notification to the customer whenever the admin adds a new comment on any order.

1.   Let’s suppose we have created a package and registered it into the composer.json file under psr-4.

2.  Create a listener for the package.

3.  Create a provider which will extend the EventServiceProvider class and here we can listen to an event and trigger a listener whenever an event dispatch.

4. Now Register the provider under config/app.php file and add the following line under ‘providers’.

5. Finally dispatch the event from controller when a comment is done on any order by admin.

So by this way, we can easily send a notification to customers for multiple events.

I’ve explored this while contributing to Laravel based project Bagisto, there are a lot more things to learn and you could also contribute to an open source E-Commerce framework.

Thanks for reading me. I hope you’ll get an idea how events and listener works with Laravel Please share your reviews on this, that will support me to write more.

Bagisto Forum!          Developer Visit!            Contact Us!          Live Demo!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home