I am trying to get my users role relation through the Auth::user() function. I have done this before but for some reason it is not working.
Auth::user()->role
This returns the error trying to get property from non-object.
In my user model I have this:
public function role()
{
return $this->belongsTo('vendor\package\Models\Role');
}
In my role model I have:
public function user()
{
return $this->hasMany('vendor\package\Models\User');
}
When I do this it returns the name of my role, so my relations are correct I think:
User::whereEmail('[email protected]')->first()->role->name
What am I missing?
Auth::user()returns eloquent instance of User model (when found).