how to get the currently logged in role symfony?

160 views Asked by At

I want to get the Role of the user currently logged. Because I want to show that in my navbar can somebody help me?

My question is about how to get the current role

2

There are 2 answers

14
Webvoid On BEST ANSWER

If I remember well, you can get roles in twig by doing {{ app.user && app.user.roles }} but you will get an array of roles.

Hope it helps.

1
Robert On

you can get from current user,when we get the role,it returns array of roles

$user = $this->getUser();
$role = $user->getRoles();

in twig

{{app.user.roles}}