Great article. I don't quite understand when and why to use pub sub model when we can create different functions and call them, for each sub task required.
That's to avoid spaghetti code. You also don't necessarily need to trigger an event if no one needs it. But it's a good practice to trigger it when you need to bind multiple service actions together, for example, think of a user booking one or multiple services, you could send an email, generate an invoice, post a message on slack,... IMHO there should be even one more step in between, fully configurable workflows that people can rely on. But if you don't have such configuration at the user level, you could bind certain actions from different controllers to the global model event bookings:created, updated, destroyed...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article. I don't quite understand when and why to use pub sub model when we can create different functions and call them, for each sub task required.
That's to avoid spaghetti code. You also don't necessarily need to trigger an event if no one needs it. But it's a good practice to trigger it when you need to bind multiple service actions together, for example, think of a user booking one or multiple services, you could send an email, generate an invoice, post a message on slack,... IMHO there should be even one more step in between, fully configurable workflows that people can rely on. But if you don't have such configuration at the user level, you could bind certain actions from different controllers to the global model event bookings:created, updated, destroyed...