[Spatie-Permissions] Possibilities of assigning roles to both teams and users

Hello everyone! I have a simple question. Is it possible to use spatie-permissions for both users and teams at the same time? For example, i have an admin role which is meant to be assigned to users only. But i also have roles which will be assigned based on subscriptions. So role package_1 is only meant to be assigned to teams. After reading https://spatie.be/docs/laravel-permission/v6/basic-usage/teams-permissions I got confused because if teams = enabled in config, it is necessary to fill in the team column with either NULL or a team id. Does this mean that with teams enabled, i can't assign roles to users anymore because it always has to be linked to a team?
6 Replies
iRelaxer
iRelaxer9mo ago
Hello, i'm bumping this thread. Is there anyone who knows the answer?
awcodes
awcodes9mo ago
Never used the teams feature in the package, but it sounds like you’re looking for a Gate. https://spatie.be/docs/laravel-permission/v6/basic-usage/super-admin
awcodes
awcodes9mo ago
It allows you to skip the permission based authorization based on your needs.
iRelaxer
iRelaxer9mo ago
Hey @awcodes thank you for your response! I have looked in to the 'Gate' feature. However it still requires a user to have a role. Which brings me back to my question, when using the teams function in Spatie-permissions, am i able to assign roles to both users and teams or am i limited to teams only?
awcodes
awcodes9mo ago
It shouldn’t require a user to have anything other than a way to return true / false / null. You can base it on anything. Ie, str_contains($user->name, ‘adam’) would return true allowing anyone with that in their name gate level access to the app.
iRelaxer
iRelaxer9mo ago
Alright @awcodes , i will think of a way to use this solution in what i'm creating. Thank you very much!
Want results from more Discord servers?
Add your server
More Posts