Home > database >  Why Laravel Echo not listening
Why Laravel Echo not listening

Time:01-12

I'm working on a small chat project, but it seems like Laravel echo is not listening, since I can see the log (message) correctly on pusher website dashboard

this is my code :

mounted: function(){
        
        Echo.private('chat').listen('MessageSent', (e) => {
            console.log(e)
            
        });
    },

This is my bootstrap.js file

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    forceTLS: true
});


my channel.php


Broadcast::channel('chat', function ($user) {
    return auth()->check();
});

By the way I see the messages on pusher dashboard, but my vue application is not listening

I'm getting in the console:

No callbacks on private-chat

CodePudding user response:

Fixed I had ->toOthers() on my broadcast so I just opened a private navigation

CodePudding user response:

Put . before event name

Chang this

mounted: function(){
        
        Echo.private('chat').listen('MessageSent', (e) => {
            console.log(e)
            
        });
    },

to this

mounted: function(){
        
        Echo.private('chat').listen('.MessageSent', (e) => {
            console.log(e)
            
        });
    },
  •  Tags:  
  • Related