* The event listener mappings for the application. Open the EventServiceProvider.php and add an UserRegistered event and SendWelcomeEmail listener to it.Ĭlass EventServiceProvider extends ServiceProvider In our case, we need to add an event and listener for user registration. Laravel provides the EventServiceProvider where you have to register the events and listeners. Registering Events and Listeners in Laravel Having said that, let’s see how to use events and listeners in your Laravel application. Here user registration is the event and sending a welcome email is a listener. Once a user registered for the application, the system should send a welcome email. One event can have multiple listeners and you will divide the code across various files(listeners) instead of writing in one place.įor this article, I will implement an event for user registration. The benefit of using this approach is that you can decouple the code. Then Laravel automatically calls the listeners when the event takes place. To trigger the action on these events, you need to register the listener. A user registered, an order placed, product added are examples of events. In this article, we discuss Laravel Events which allow you to register a Listener when a certain action occurs. Each of these features helps developers to create a more robust application. Broadcasting, File Storage, Notifications, Events are some of them. Laravel ships with several nice features to simplify the development.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2023
Categories |