So events that implement should broadcast are actually handled by the Laravel queue. Laravel queued jobs are extremely useful for running functions in the background. That is asynchronously to a request. However, they do require that you spin up a new process in yet another terminal tab.
In production, you've probably already got it running. and it's actually really quite easy to get it running on our local machine as well. But let me show you just a few other workarounds besides actually spinning up the job queue that'll help us see our real-time data. The first option you have is to use the should broadcast now interface instead of should broadcast.
This means this event runs synchronously. It doesn't get sent to the queue. So back in the browser now, if I refresh the page on the right-hand side, sure enough, we get our console log on the left-hand side. So what is happening here?
js is set, and then when we refresh the page on the right-hand side, the server-side event fires inside of that route handler. that sends the message back to the original browser. Of course, I can reload the page on the right-hand side as many times as I want, and literally every time the event is fired on the server, the client over here receives the event. Awesome.
So that is one option. However, in production, you probably want your events to stay running in the job queue. If that's the case, you should put this back to should broadcast, And then in your local environment, if you don't want to start up the job queue, you could set the queue connection here to sync instead of database. And now anything throughout your entire app that is meant to run on the job queue in production locally will just run synchronously in the request.
This works exactly the same as before. Finally, I'd like to point out that we can also see these events inside of the network tab. So if I open up my network tab here, filter to just WebSocket requests, and then open this particular request right here, you can see all the data coming down through this event. So you can see here are the instances of the event being received down.
And here is just kind of a health check from our client side to say, okay, we still have the server side connected. In order to prove that to you, I will just clear out all the events in here. Then I'll refresh this page one more time. And sure enough, you can see here is the event.
Its name is App Events Hello World. And then the data is, let's pull this out just a little bit, the message of Hello World.