Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

6ber6ou's avatar

"romanbican/roles" Package and Get Roles Names

Hi all.

I use this great package : https://github.com/romanbican/roles Everything is ok except I don't see how to get the roles names of the user.

0 likes
1 reply
bashy's avatar

I added a relation in User.php model

public function roles()
{
    return $this->belongsToMany(config('roles.models.role'));
}

Then eager load the roles into the User collection

$user = User::find(1)->with('roles');
return $user->roles->name;

If that's what you wanted.

Please or to participate in this conversation.