In this episode, we start by pointing out that while we're listening for events in our application, these events aren't very useful unless they come with some data. So, we walk through adding a simple public property—like a message
—to the event and see how it gets broadcast to everyone connected to the channel. This is a nice way to demo that data is really being sent out in real time.
Next, we explore a more realistic scenario: instead of just using a hardcoded string, we fetch a user from the database and pass that whole user object to the event. This lets us see in the browser how Laravel automatically serializes the user data into JSON and includes it in the event payload.
Along the way, we point out some important considerations. For example, only public properties of the event will be included in the broadcast. If you set a property to protected, it won't show up in the broadcasted data—something to be aware of!
Finally, we caution about security and performance: broadcasting entire models (like users) can expose sensitive data and send much more information than necessary. So before moving on, we mention the need to be careful about what you include in your broadcasted events, hinting that we'll look next at how to control exactly what data is sent.