Reputation: 589
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
Reputation: 1
Below steps worked for me.
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
});
Upvotes: 0
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
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