I have an issue.I am accessing my pusher info from .env file
through process.env.VARIABLE_NAME inside bootstrap.js
(As defined inside laravel Docs in broadcasting section), but it gives me an error.I am working on laravel Pusher with VueJs.
bootstrap.js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
Vue.prototype.$echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
forceTLS: true
});
My Vue File
mounted() {
Vue.prototype.$echo.private('expense')
.listen('ExpenseNotification', (e) => {
console.log('irfan ullah shakir');
});
}
Error:
[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'private' of undefined"
Code works fine to broadcast event to pusher, but have problem in receiving through 'Echo' inside vue mounted hook
Latest comments (8)
Hy, I found solution.I just paste
inside
app.js
and it is working fine now.Second, I changedVue.prototype.$echo
towindow.Echo
inside bothapp.js
andVue mounted Hook
(where I am listening channel).Just gotta ask,
Echo
is installed right?npm install --save laravel-echo pusher-js
? As for the comment below,Presence Channels
areprivate channels
Event receiving in Pusher: dev-to-uploads.s3.amazonaws.com/i/...
Ys, Echo is Installed
Package.json: dev-to-uploads.s3.amazonaws.com/i/...
On the sample in Laravel Doc it assigns the Echo to window.Echo. laravel.com/docs/7.x/broadcasting#...
Have you tried this way?
It gives me an error: "Echo is not defined", I also tried window.Echo
replace Echo.channel with window.Echo.channel......
The link you sent is for
Presence Channels
I am usingprivate channels
laravel.com/docs/7.x/broadcasting#...