DEV Community

Discussion on: Use laravel .env variable in Vue

Collapse
 
irfanullahshakir profile image
Irfan Ullah Shakir

I have an issue I want to access variables inside .env through process.env.VARIABLE_NAME, but give me some 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'

Collapse
 
grahammorby profile image
Graham Morby

Have you re complied ?

npm run dev
yarn run dev 

etc

Collapse
 
irfanullahshakir profile image
Irfan Ullah Shakir

Thank you I already solved it, here is my solution:
dev.to/irfanullahshakir/comment/15en1