JPMusket's avatar

Broadcasting not making it to the front end.

I'm working on a site and wanted to make a page get alerted when a record is added. So I started following the Laravel Docs on Broadcasting with Pusher but I hit a snag. I'm not seeing the Broadcast event when I use listen on that page. There are no errors in the javascript console or in the Laravel logs. I do see connections in the pusher debug, so I think that part is working.

I'm pretty new Laravel so this is probably something minor I forgot or messed up somewhere, any help would be appreciated. Here's my code:

App/Events/NewMessage.php

In my controller, on the store() function I have:

broadcast(new NewMessage($att['user_id'],$att['message_id']));

resources/js/echo.js

import Echo from 'laravel-echo';
 
import Pusher from 'pusher-js';
window.Pusher = Pusher;
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
    forceTLS: true
});

On the blade template, I have:

<script type="module">
        Echo.channel('messageLog').listen('NewMessage', (e) => {
            alert('Gottem');
        });
    </script>

I'm not sure if anyone would need to see anything else, but let me know and I can add it.

0 likes
0 replies

Please or to participate in this conversation.