1 year ago

Auth::user() not returning all elements

Posted 1 year ago by hjortur17

Hi, I'm trying to get the role of every user but Auth::user() is not returning it.

I have this in my master.blade.php

window.App ={!! json_encode([
    'signedIn' => Auth::check(),
    'user' => Auth::user(),
]) !!};

and this in my .js file

isAdmin() {
    console.log(user);                                               => {id: 101, name: "Hjörtur Freyr Lárusson", username: …}
    console.log(user.role);                  => undefined
    console.log(['admin'].includes(user.role));  => false

Any ideas why this is happening?

This is the full return from user

avatar_path: "http://project.test/avatars/fhVx37enhNNcaBnUDsQv2iHtymbbKKPiDPml2AWr.jpeg"
created_at: "2019-05-21 17:39:25"
email_verified_at: null
id: 101
name: "Hjörtur Freyr Lárusson"
updated_at: "2019-05-21 18:02:02"
username: "hjortur17"
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()

Please sign in or create an account to participate in this conversation.