You can do that like you would foreach any database records.
Find user roles
So I just finished Jeffrey's short ACL tutorial on the 5.1 update series, and I'm wondering how to go about listing all users, along with their roles in the view. Likely with something like $user->roles()->label as it loops through a list of all users to output them (or a 'getRole()' function if possible).
Also, since I want my users to be defaulting to role_id of 4 ('member'), how would I go about doing that upon their registration?
Been staring at this project for so long it is beginning to drive me crazy, I think.
Thanks very much!
@Beechey $user->roles is the property and $user->roles() is the relationship. The property should give you a collection of roles, so you can iterate over the collection and get the label for the individual roles.
$roles = $user->roles;
foreach ($roles as $role) {
echo $role->label;
}
Please or to participate in this conversation.