Mail::send() inside the checkout controller. A second copy inside the API controller. Then someone adds the chat webhook to one copy and forgets the other. Every project has this code. I have written it more than once.

Laravel 5.3 came out this week, and the two big pieces, Notifications and Passport, both point the same way. The application is no longer a thing that renders HTML. It is a core that talks to browsers, mobile clients and third parties, and HTML is one of the outputs.

Passport is a full OAuth2 server in a package. If you ever hand-rolled token auth for a mobile app, you know how many small decisions there are to get wrong. Now it is a boring dependency. Auth is the code I most want to be boring.

Notifications interest me more, because they force a separation people skip. There is a business fact: an order was paid. And there are delivery details: send an email, write a row for the in-app bell, ping a chat channel. Different layers. The checkout code should announce the fact and stop:

event(new OrderPaid($order));

A listener catches it and decides about delivery. The notification class lists channels in via(), and one more channel later is a change in that one class. Checkout does not know chat exists.

The test I apply: if marketing asks for SMS tomorrow, how many files change? The right answer is one.

You do not need Laravel 5.3 for the idea. An event and a listener exist in any stack, even in our old Kohana project. The release just makes the good structure the lazy option. On a Friday evening that is the only option people take, me included.