-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: User with diferent Roles and Companies #888
Comments
This package associates role/permission models with other (usually User) models using polymorphic relations. However, you are free to extend the package code to link in other relationships as you wish. Alternatively if your application supports it, having a different User object/model per-company could give you quick implementation with minimal code complexity. |
I have the same issue as @georgecpacheco, but instead of different roles per company, I need different permissions per company. For example: I was thinking that adding a column named Maybe you have a suggestion which files need to be modified to get the desired result? |
i have question , how to add company_id into roles table ? or how to add company_id into permissions table? |
@vchampanery just publish the migration with the follow command: |
@drbyte I ended up editing the How can I update the permissions() function so it will also update the |
@Dennis1502 did you sort out adding the additional column into your custom code? |
@drbyte Hi, No I had to made another solution for this problem: I generate a unique role for every user now. So when a user is connected to multiple companies, I'll create a role for the user_company like: role_[user_id]_[company_id]. When the user is connected to 3 companies, he will be assigned to 3 unique roles so you can change permissions on every role. It is a kind of hack-around, but I had no other solution, unless I would build the whole permission logic by myself, but there is not enough time (and knowledge). |
So is there no out of the box way to add another column to the roles table so you can have company specific roles? If there isn't can i get some guidance on how to extend the package code to implement this? I can't use polymorphic users because i want a user to have multiple roles for one company. |
Hi! I think you can create a pivot table "company_table", then make a model "CompanyUser", and use that model to assign specific roles to each company-user relationships. |
@nicolaspennesi that's indeed what I did. It is not the best solution, but it works for now. I have to refactor it anyway ^^ |
@nicolaspennesi could you please give some more info on your solution? |
I had a similar problem. Have a look at these articles: https://laravel.com/docs/5.8/eloquent-relationships#defining-custom-intermediate-table-models If you only need to assign users roles, this works nicely. |
well look what I found and check if it works for you guys write this in your users model.
|
Hi @georgecpacheco |
Hi @georgecpacheco |
The solution is on documentation |
Thanks for this but these are teams permissions, I have read them. We cannot create a new column inside the roles table where people with a specific role could create further roles with a company_id associated (Those roles which are added by a user will not be visible to other companies, you can say company specific) |
@MuhammadTalha944 maybe i don't understand, but teams looks exactly what you are looking for to me, also you can overwrite/customize as you need |
Have you tried it ? Is it for a user can create multiple roles under a company without breaking spatie gates and policies ? |
@MuhammadTalha944 i'am using Teams Permissions for allow user multiple roles creation under a company without breaking spatie gates and policies |
Ahh, Glad to hear that finally, could you help me out please. How you achieve that how you managed to have company id inside spatie tables and all that using teams feature. |
I did only follow these indications |
The problem with that @fredsal is you have to create a duplicate role for each individual team don't you? My scenario is I have teams, people are assigned to the teams and from there they should have individual roles/permissions per team which are based on a global default. The way I see: https://spatie.be/docs/laravel-permission/v5/basic-usage/teams-permissions working, if you have to create new roles for every single team? |
@tonypartridger read again and look for |
It's overly complicated, you can do this with this package by adding the team support, see: https://spatie.be/docs/laravel-permission/v5/basic-usage/teams-permissions |
Hi! I need to implement in a system where a user can be from different companies with different rules for each of them.
Ex: User X - Company A - Admin
User X - Company B - Manager
Remembering that my system is not Multi Tenancy.
It's possible with this package?
The text was updated successfully, but these errors were encountered: