Heads up: The chat mechanic (conversations and messages) and UI was already built, this tutorial is simply about adding real-time functionality. I mea

Adding real-time chat in 14 lines of code with Laravel Reverb and Livewire

submited by
Style Pass
2024-07-10 13:30:13

Heads up: The chat mechanic (conversations and messages) and UI was already built, this tutorial is simply about adding real-time functionality.

I mean, sure, when you want to reach out to a developer, some sort of messaging feature makes sense, but a convo usually looks like this:

(I do have other legit reasons to use WebSockets on Laradir on the horizon, but Messaging is the only live feature that really makes sense to try it out with for now.)

I've opted for installing Reverb into Laradir, rather than setting it up as a separate service. At this stage, this is fine and keeps the whole thing manageable.

I'm running Reverb locally as a Laravel Herd service. So during development I'm not actually exercising the Reverb installed in my application, I'm just connecting to an "external" service.

The broadcastOn method just tells Laravel which channels to broadcast on. It can accept model instances in place of Channel instances and will use predictable conventions to set channel name and other details.

Leave a Comment