Setting up Roles
Having trouble understanding what is a role and roles. Looks like I can setup the initial role-id when sign in up in config/voyager: But why when I sign up I new user it says "No Results." What's the difference between Role and Roles.
'user' => [
'add_default_role_on_register' => true,
'default_role' => 'member', <---CHANGED FROM TRIAL TO MEMBER
'namespace' => \App\Models\User::class,
'default_avatar' => 'users/default.png',
Hi,
The role
is the main role of the user, roles
are any additional roles of that user:
In most cases you would use the main role and associate it with the user plan.
You can add additional roles for other permissions that you might want to grant to a specific user.
You can learn more about roles here at the Voyager docs:
Let me know if you have any other specific questions 🙌
Yes, this is how it works. I just tested it and can confirm that it works.
- Update the voyager config and set the default role name to the one that you want
- Regarster a new user via the /register route
- The primary role will be set to the newly specified on from the config
In my case the role was with id 7:
The primary role is set be defining the role_id
and not in the additional roles.
so role-id and role should be populated right. However, for me I must select a roles that match's the role in order for role to populated. 2nd if the role-id is set why isn't it populating the role name in the role column matching the role-id.
In your example i assume the output is Role-ID = 7 Role = Member Additional Roles = No Results
When I sign a new user, I get Role-ID = 7 Role = No Results Additional Roles = No Results
For me to fix role I must Role-ID = 7 Role = Member Additional Roles = Member
If I set role to primary role to member and attentional roles to staff. Role and Roles are both Staff. Im just not sure this is working right.
Hi,
Ah yes I see what you mean, this is just a display issue in the admin and not a bug in the way that roles work.
What you can do is:
- Edit the User bread:
your-domain.com/admin/bread/users/edit
- Find the Role relationship
- Change it to
BelongsTo
instead ofBelongsToMany
:
That way you will get the name of the main role rather than the additional roles.
Made the suggested change and it caused an error when trying to reg a user. Is there any knowledge base for this specific page. What are these heart relationships? Is the BREAD for each item allowing that item to access those things? How do I hide ones I dont need from the users panel. Since the change to belongs to, several more have been added to the user panel.
EDIT: adding a user in the admin panel did seem to work. But not on the typical register page. Is the reole-id still supposed to show? How do I remove those other unused attributies of the user.
Did you make any other changes as this seems to be working for me? You still need to have the default role defined in your Voyager config.
Also the Voyager BREAD does not affect the frontend authentication so there must be something else that you've recently changed to break your frontend authentication that way.
Happy to hear that!
Yes, just update your BREAD and uncheck the 'browse' checkbox for those.
You can learn more about the BREAD system here:
Also check out the Voyager into videos where all of this is well covered as well: