Has anyone gotten Laravle Echo to work in a Livewire Component?
I have broadcasting working in my livewire components using presence channels, can accurately see who's in the "room" (on the page). I want to be able to see when a user leaves the page so I can reflect that in the UI. I figured this would be done with the Echo.leaving event, but apparently that's not how that functions. The below assumes that some Echo javascript thing would be the approach, but if someone has an easier way, that would be great, as what I'm trying to do doesn't work.
Regarding attempting the Echo/javascript approach....
I have the config published, and broadcast notifications are working within Filament. However, I need to handle events using Laravel Echo in javascript (I think) for a specific use case in a livewire component, and I get Echo not found. I tried adding the bootstrap.js file with the imports per the Laravel Echo documentation and still nothing.
From reading on github issues, it looks like the
filament/views/components/layout/base.blade.php
is where Echo gets pulled in:
This is happening via the EchoFactory, which looks to just be a reference to Echo itself defined in vendor/filament/filament/resources/js/echo.js
.
My page is already extending components/layout/base
so I would think that this bit of code would already be working, but I can't seem to do anything on the javascript side. Broadcasting is working fine on the server-side.
Anyone know I can listen to events from javascript? Specifically broadcasted presence channel events.1 Reply
anyone have any ideas on this? I believe to accomplish what I'm after, I need to be able to use Laravel Echo in javascript on my livewire component. How can I do that? It doesn't seem to see Echo.
ok, I think I actually figured it out (maybe). I noticed on some questions online that folks were saying that Echo isn't loaded until after livewire so I wrapped my Echo code in an event listener on the
DOMContentLoaded
event. Seems to be functioning correctly now.