David Machara
David Machara

Reputation: 589

laravel Echo --> Cannot read property 'channel' of undefined

iv been trying to solve this since morning...i keep get this error..

vue.js:1743 TypeError: Cannot read property 'channel' of undefined 

i am trying to listen on a channel using this code.i already tried using Echo.channel that didn't work so am using the code below which also seem go generate the error i mentioned

listen(){
window.Echo.channel('tmp-chanel')
.listen('NewBidMade',(auction_item) => {
console.log('-------wakanda-------');
// this.item = auction_item;
});
},

any ideas or possible solutions are welcome

Upvotes: 5

Views: 11391

Answers (3)

Ayaz
Ayaz

Reputation: 1

Below steps worked for me.

  1. I have created file to below path and add this code.

resources\assets\js\laravel-echo-setup.js

import Echo from 'laravel-echo';
       
window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ":" + window.laravel_echo_port
});
  1. restart system.
  2. run this command : laravel-echo-server start

Upvotes: 0

David Machara
David Machara

Reputation: 589

My problem was that my script tag had the defer attribute. Removing it fixes the problem with the script.

<script src="{{ asset('js/app.js') }}" defer></script>

Upvotes: 10

Roland Allla
Roland Allla

Reputation: 396

To use Laravel Echo, first you have to import it on bootstrap.js

resources/assets/js/bootstrap.js

Please check if this line of code are uncommented:

import Echo from "laravel-echo"

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

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'your-pusher-key'
});

Note: If you use pusher, update the code with your key-s

More info: https://laravel.com/docs/5.6/broadcasting#installing-laravel-echo

Upvotes: 2

Related Questions