arslan asghar
arslan asghar

Reputation: 1

Laravel-mix in Laravel-7 and vue.js error:(Uncaught Type Error: Cannot set property '$Gate' of undefined)

I'm just a student and fairly new using Laravel with vue.js. I'm using Laravel-mix version 6.0 in laravel-7 and after running mix I get this error (Uncaught Type Error: Cannot set property '$Gate' of undefined) in public/js/app.js.console error description. Due to this the routes are not working, and are visible disable.

The error line in app.js:

Vue.prototype.$gate = new _Gate__WEBPACK_IMPORTED_MODULE_2__.default(window.user);
My resource/assets/js/app.js file contains following code:

import Gate from "./Gate";
Vue.prototype.$gate = new Gate(window.user);

laravel-mix webpack is applied on this file.

my gates file contains following code:

export default class Gate{

    constructor(user){
        this.user = user;
    }


    isAdmin(){
        return this.user.type === 'admin';
    }

    isUser(){
        return this.user.type === 'user';
    }
    isAdminOrAuthor(){
        if(this.user.type === 'admin' || this.user.type === 'author'){
            return true;
        }

    }
    isAuthorOrUser(){
        if(this.user.type === 'user' || this.user.type === 'author'){
            return true;
        }

    }
}

Any help would be much appreciated. Thanks.

Upvotes: 0

Views: 701

Answers (2)

Hamid
Hamid

Reputation: 384

You have to import Vue before calling prototype
by this command above your app.js:
import Vue from 'vue/dist/vue'

Upvotes: -1

Marco F
Marco F

Reputation: 1

try this:

import Gate from "./Gate";

const $gate = new Gate(window.user);

Vue.prototype.$gate = $gate;

Upvotes: 0

Related Questions