laravel Echo --> Cannot read property 'channel' of undefined
Asked Answered
S

3

5

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

Scraperboard answered 28/6, 2018 at 10:2 Comment(0)
S
10

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>
Scraperboard answered 28/6, 2018 at 10:48 Comment(0)
F
2

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

Fantasist answered 28/6, 2018 at 10:42 Comment(1)
yes .all those where availble. my problem was the defer attribute on my script tag.Scraperboard
D
0

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
Dromedary answered 1/12, 2022 at 5:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.