36

I'm trying to setup Laravel Echo with pusher, to implement real time notifications.

First, i have installed Laravel Echo and Pusher:

npm install --save laravel-echo pusher-js

After this, in bootstrap.js i have uncomment the code (as guide say):

import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'my_key',
    encrypted: true
});
Echo.channel('orders')
    .listen('TestEvent', (e) => {
        console.log('pippo');
    });

I have run gulp and now when i visit the page, i get this error:

bootstrap.js?5e63:50 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_laravel_echo___default.a.channel is not a function
baikho
  • 5,203
  • 4
  • 40
  • 47
Mistre83
  • 2,677
  • 6
  • 40
  • 77

1 Answers1

113

Changing Echo.channel('orders') to window.Echo.channel('orders') should fix that.

baikho
  • 5,203
  • 4
  • 40
  • 47