You need to configure the relationship for that to work.
https://laravel.com/docs/5.1/eloquent-relationships
Then you can do:
Auth::user()->role->name
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I want to get the specific user role for the logged in user, but I don't know what to do after getting the Auth::user. I have the following code now:
public function index()
{
$roles = Role::all();
return view('admin.dashboard', ['roles' => $roles]);
}
My view where I try to get the role:
<p>
{{ucfirst(Auth::user()->name)}} - {{ Auth::user()->$roles->name }}
<small>Member since {{ucfirst(Auth::user()->created_at->format("M d Y"))}}</small>
</p>
Everything is in the same table except the user roles and I dont know how to get into there, i tried this: {{ Auth::user()->$roles->name }}
Please or to participate in this conversation.