Solved
scraghty

Oct 2nd, 2024 01:59 PM

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',

Screenshot 2024-10-02 134306.pngScreenshot 2024-10-02 134336.png

bobbyiliev

Oct 2nd, 2024 02:07 PM

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:

Voyager Roles and Permissions

Let me know if you have any other specific questions 🙌

scraghty

Oct 2nd, 2024 02:52 PM

If the config is set to use "member" as the default role. Shouldn't it have role-id and role = member? Even if I set role in admin menu it wont populate until I select a roles as well.

bobbyiliev

Oct 2nd, 2024 03:18 PM

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.

scraghty

Oct 2nd, 2024 04:32 PM

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.

Screenshot 2024-10-02 163223.png

bobbyiliev

Oct 3rd, 2024 12:00 AM

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 of BelongsToMany:

That way you will get the name of the main role rather than the additional roles.

scraghty

Oct 3rd, 2024 02:40 PM

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. Screenshot 2024-10-02 163223.png

error.pngerror2.png

bobbyiliev

Oct 3rd, 2024 11:31 PM

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.

scraghty

Oct 4th, 2024 01:04 PM

whoops, forgot I put the voyager/config default user back to 'trial'

Everything seems to be as I would expect. Any way to hide these unused attributes? Not sure I want to remove them for future proofing.

error4.png

bobbyiliev

Oct 4th, 2024 11:55 PM

Best Answer

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:

Voyager BREAD

Also check out the Voyager into videos where all of this is well covered as well:

https://voyager.devdojo.com/academy/