How to Add Custom Roles to Teams in Laravel | Full Tutorial
Chapters7
Overview of using Laravel teams, creating a personal team for the user, and starting a new team.
Tony Xhepa walks through adding custom team roles in Laravel 13, showing how to define levels, permissions, and invitations for owner, admin, writer, editor, and member roles.
Summary
In this practical walkthrough, Tony Xhepa demonstrates how to extend Laravel's team feature with custom roles and permissions. He starts by inspecting the starter kit’s team setup and then creates a project with personal teams linked to users. The tutorial emphasizes not just owner, admin, and member roles, but introduces a new custom role system with a numeric hierarchy (100 for owner, 80 for admin, 60 for editor, 40 for writer, 20 for member). Tony links roles to specific permissions like update team, create invitation, and cancel invitation, and shows how to assign these roles to invited members. He also explains how to manage invitations (send, cancel, and accept) and how the Livewire component handles team and member data. The video walks through modifying the role hierarchy, adding a new role (editor), and testing with multiple invited users who join as different roles. Finally, Tony demonstrates permission checks by attempting operations as admin, editor, writer, and member to validate the effective access levels. The session includes a useful cloud-code suggestion about gaps in the numeric ladder to future-proof role additions. The end result is a hands-on guide to implementing and testing custom team roles in Laravel 13 for more granular access control.
Key Takeaways
- Custom role hierarchy: owner 100, admin 80, editor 60, writer 40, member 20, with gaps of 20 to allow future roles without reordering.
- Permissions mapped to roles include create invitation, cancel invitation, update team, and delete or manage members depending on the role.
- Livewire-based UI flow: invite member modal passes the team context and selected role, and invitations are processed via a dedicated create invitation method.
- Invitations work end-to-end: you can send, cancel, and accept invitations; invited users join a team with the assigned role and corresponding privileges.
- Database reset and migrations are demonstrated with PHP artisan migrate:fresh --seed and composer install to ensure a clean test environment.
- A new role (editor) is added alongside owner, admin, and writer, with editor granting a subset of admin permissions (update team, create/cancel invitations).
- The approach supports future expansion by reserving numeric gaps between levels, enabling easy insertion of new roles without reordering existing ones.
Who Is This For?
Laravel developers who want fine-grained access control within teams, especially those migrating to Laravel 13’s team features and looking to add custom roles beyond owner, admin, and member.
Notable Quotes
"Hello friends, Tony here."
—Opening greeting and channel branding to set the tutorial’s tone.
"If we want more roles?"
—Introduces the motivation for adding custom roles beyond the default ones.
"The team role has the case for the owner admin and the member."
—Describes existing roles and the need for extending them with custom roles.
"Gaps of 20 let you insert up to 19 intermediate rows between any two without reumbering."
—Cloud code suggestion about designing the level system for future roles.
"Editor can update the team, can create the invitation and cancel the invitation."
—Shows the permissions granted to the newly introduced editor role.
Questions This Video Answers
- How do I add a custom role in Laravel 13 teams?
- What are the best practices for role hierarchy and permissions in Laravel teams?
- How can I test Laravel team permissions with Livewire components?
- Can I expand Laravel team roles without renumbering existing ones?
- What are the exact permissions for each role in a Laravel team setup?
Laravel 13Laravel TeamsCustom RolesTeam PermissionsLivewireInvitationsRole HierarchyDatabase Migrations
Full Transcript
Hello friends, Tony here. Welcome in today's video again. I'm going to work with teams for one more time. Yeah, if you go to Laravel documentation and uh search for team. So you can go here on the starter kits, we have this team section and yeah, you can read what we have in here and I have prepared a project. Here is the project. Now let's go and register. And if we register here with the user because I use teams is going to create the team with the user and it's going to assign that team which is going to be the personal team.
So if I go here settings we have teams section and yeah this is a personal team for this user and we can create team. So let's create a new team. Let's say for example just example I'm going to create and we are on the examples teams example we can update the name we can invite the member so we can see the team members right now is only this one which is the owner. Now in this video I want to work with this role. So if I want to invite members, we have by default selected this member role and we have also the admin role.
But what if we want more roles? If we open the project and uh for example, let's open this model here. If what a team themes settings themes let's see let's open first the resources views pages and we have all settings and we have teams and here we have the accept invitation cancel delete edit and invite member model. Okay so this is a full page liveware component. First we associate the team then string with invite email and invite role by default is member. So you can see okay on the mount we say this team the team theme team here because if we open edit okay so we have update the team update the me member membership populate team data we have here the invite member model and it's going to pass here the team for that in the invite member model we have here team and we say this team the dollar sign team.
Then we have the create invitation method first using the get authorize invite member then validated the invite email and the role and we can see the role is rule enam team role which is the team role is enam. If we go to enams so we have a team role and also team permission. So team permission update team delete team add member update member remove member create invitation and cancel the invitation. The team role has the case for the owner admin and the member. So if I see here we have the only the admin and the member.
So we can say admin and the member. We cannot assign owner to what the user is going to be invited. So we can assign only the member role or the admin role not the owner because we are the owner. We created the team. That's okay. So if I want uh we can create a case here for that role. So we can see the name is team role. Let's create another one. Let's create a case for the writer I'm going to say and this is going to be writer also here then we have the label method we have a permissions returning this uh match this self owner team permission cases all we have this team permission and I'm going to open side by side all the cases So update, delete, add member, update member and so on because this is the owner.
Then for the admin has added only the update team, the create invitation and the cancel invitation. So update team, not delete the team. The admin cannot delete the team and also create and cancel the invitation. cannot add member, update member or remove the member. Then we have the self member which is an empty array. So member has not uh permissions. Let's say self and we created the writer and we can assign roles if we want permissions if you want. I'm going to assign only two permissions the create invitation and cancel invitation. So let's say team permission create invitation and also team permission cancel invitation.
Okay, I think we are good here with permissions as permission is is going to return boolean in array permission pass in this permissions. Then we have a level get the hierarchy level for this role. Now here we have owner admin member. Then we have check if this role is at least as privileged as another role. And here is going to check based on this level. So for example if this level is greater or equal with the role level. So if we want to add our self writer. Now we need to give it a number here a level.
And because we have the 3 2 one, let's give it this two, this three, and this four. And it's going to be okay because the writer is let also here. The writer is greater than the member than and smaller than the admin. The admin is greater than writer than the member. And the owner is the owner is greater than admin. writer and the member. But what if I want to add another role? Okay, so if I want to add another role in the future or now, let me just uh let me select this and I'm going to ask let's ask the cloud code and I asked the cloud code.
So suggest me if I want to add another custom role. What numbers is the great idea to add for the owner admin and another role I want to create and rider and member and good questions. He suggest me to add to the self owner to the owner 100 then admin 80 then new role for example editor 60 writer 40 and member 20. Why this numbers gaps of 20 let you insert up to 19 intermediate rows between any two without reumbering. So if we want to add in the future more rolls, if we added 100 here on the owner, so let's add 100 and 80 here.
And if we want to add another roll here, we have the space from 80 to 100. So this is very good suggestion. And I'm going to add this one. So 80 to the writer 40 and here 20. So let's close the cloud code. But uh and let's add also another one. We have member. Let's add a case for what we had. Yeah. Editor. And I'm going to say this is going to be editor. Let's come here and let's give it also permissions to the editor. So self editor and this is going to have some permissions.
So team permission and I'm going to say add member the editor. I'm going to give it a permission to add member. team permission create the invitation and team to cancel the invitation and we have update the team. So let's also use the same here update the team not nothing else. So the editor is going to be the same as the admin. Let's scroll down. Now we have also here to add the editor. So self editor and we're going to give it 60. Then I think we are good here. Team permission. We can create more permissions here if we want, but I'm going to leave it like this for now.
And let's go and run here PHP artisan migrate fresh optimized clear. And I'm going to run the composer run that. Let's go and sign up with a new user. So, we have yeah, not example, we have a fresh database. Let's create a new team and I'm going to name it example. Now, for the email, I'm using mail. I have added the credentials in my MV file. Now, we are on the example. we can update because we are the owner. We don't have any members yet here. So, let's invite member. Let's use fake filler. And uh I'm going to choose the admin first.
I'm going to create four members. I'm going to invite four members. So, this is the admin. Another one. This is going to be the Yeah. member. Another one for the writer. Yes. And another one for the editor. And yeah, we have two fails. Let's see if I come here. We have this one few seconds ago. My kabi and new huab. So this one is sent. I'm going to delete this. Cancel the invitation for that one. And also for this one we have only admin and the writer. So let's invite another one for the member. Running.
Done. And another one. So we have admin writer and the member. A new invitation for the editor because we don't have editor. and running done. So we have here four invitations. Let's start by this this one which is lo okay if I come here loses the editor. I'm going to copy the email for this one and let's open in another browser. I'm going to register with fake filler. Just use this as an email. Create the account. Okay. And then we can copy the link for the invitation. Paste it right here. Okay. We are on the example.
If I go now to settings teams, we have the uh this which is created by default when we are register and the example and the role is editor. If I come here, we can update the name. We can invite the member. So let me just see if I go to editor. Editor can update the team, can create the invitation and cancel the invitation. Very good. So if I say just create the invitation, I'm going to create an random invitation. Send. Invitation sent. And as you can see, we have the cancel invitation. We have this link.
Okay, good. I'm going to log out. And let's go again here because we have uh the editor. This one we created. Now let's create another user for the member. Going to copy this one. Come here. Register. Use a fake filler. Paste that which is a member. And now, yeah, we need to copy for this mimmer. Yeah, this one. We need to copy the link and just paste that link here. We are on the example and let's see if I go to settings teams example, we are member. We just can see this. Yeah, we can see this one and see the team members and pending invitations.
Okay, good. Let's log out. Let's go and see now we worked with editor member. Now let's see the writer. I'm going to copy the email here. Let's register. Use fake filler. Paste that in. Create account. Now let's see my copy. Where is this? My copy is this one. We need to copy the link. And just paste that link here. Hit enter. We are on the example. If I go to settings, teams example, we are writer and we can edit the team. Okay. So if I see now the writer where is the writer has the create invitation and cancel We cannot change the name but we can and we can cancel the invitations as you can see here.
Good. I'm going to log out. And now let's test the last one which is the admin. And the admin is this user here. this email here. So, we need to go and register with a fake filter. Just update the email here. Create. Okay. Now, let's see again. What was the hotel? This one. This one. Let's copy the link. Come here. I'll paste. Hit enter. We are inside the example. And if I navigate the settings teams example we are admin click here we can edit the team we can invite members and we can cancel the members and we can see also here.
But what if I change on the admin? So for example right now we can update the name. If I comment this update the team and save. Come here. You can see we cannot update. We are this one which is an admin but we cannot update that because we moved the permission and now we can update. Okay friends, this is how we can work with teams and roles in Laravel 13. Now that's it all about what I wanted to show you in this video. If you like such a videos, don't forget to subscribe to my channel, like the video, share with your friends because it's going to help me to rank on YouTube and also it's going to motivate me to create more video about Laravel.
All the best and I'm going to see you in another video.
More from Tony Xhepa
Get daily recaps from
Tony Xhepa
AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.









