In this episode, we dive into broadcasting events to private channels in our Laravel project. Now that we’ve got our private channel set up and authorized, it’s time to actually send an event through it. We work through creating a new event (like OrderDispatched
), figure out how to dynamically broadcast this event to a channel that includes the user’s ID, and set up all the PHP-side essentials to make broadcasting work seamlessly.
On the front-end, we wire up everything so that when our event is broadcast, the client hears about it and updates the UI right away. As part of the walk-through, we model a simple dashboard scenario: when an order is dispatched, the interface instantly reflects that state change. We see how to use Alpine.js to respond to the broadcast and display order information dynamically.
You’ll also see how to set up an orders
table, generate fake data with factories, and make sure orders are related to users. This is handy for authorizing broadcasts only to users who should see them, which we hint at and will build upon in the next episodes.
By the end, you’ll have all the pieces connected: the backend broadcasts an event relevant to a user, the frontend listens on a private channel and updates accordingly, and you’re ready to power real-time features like notifications or order status updates throughout your app.