[Vuejs]-How to check if a user is online in laravel vue.js

0👍

Well, the most easy way is to define it like this:

 ```<script>
        window.loggedIn = {!! json_encode([
        'signedIn'=>Auth::check(),
    ]) !!};
    <script/>```

That way you will have a global variable named “loggedIn” that will give you true or false if the user is online or not.

0👍

Looks like you are using lodash to check if the user exists in the onlineusers array.

This is not an error, this is expected behavior, just like the docs say for the _.find() method:

Returns the matched element, else undefined.

I would recommend using the _.some() method:

checkUser() {
    return  _.some(this.onlineusers, ['id', this.contact.id});
}

Just like the docs say:

Returns true if any element passes the predicate check, else false.

Leave a comment