In this episode, we dive into getting Laravel Echo set up with a Nuxt client so we can work with real-time events in our application. Since we don't want Echo running on the Laravel backend, we focus on installing it purely on the client side.
We'll start by installing both laravel-echo
and pusher-js
with npm in our Nuxt project. After the packages are in, instead of cluttering our app components with setup code, we create a dedicated Nuxt plugin. You'll see how to structure this plugin, why we name it with the .client.ts
postfix, and where to register it in nuxt.config.ts
so it's only available on the client side.
Next, we'll scaffold out our plugin. Initially, we'll just log to the console to make sure it's running, and then move on to importing Echo
and Pusher
within the plugin. There's a bit of a workaround with assigning Pusher
to the window
object (thanks, Echo!), but it’s nothing we can’t handle. We also set up the Echo instance using the broadcaster and keys, grabbing details like the websocket host and app key from our Laravel setup.
Finally, we check if everything’s wired up by looking for a successful websocket connection in the browser’s network tab. You'll also see what happens when things break (like killing the websocket server) to make troubleshooting easier. By the end, you'll have a Nuxt client that's talking happily in real-time with your Laravel backend via Reverb. Ready for the fun stuff: listening to events and making your app interactive!