Replies: 2 comments 4 replies
-
It is not possible laravel-permission/src/Traits/HasRoles.php Line 146 in 2cc5362 Make your own custom trait, or a custom method |
Beta Was this translation helpful? Give feedback.
-
There are probably additional multiple-team kinds of functions that should be done this way, beyond just assignRole(). For example, if you were to create a function within your own app to do this proposed new feature, you'd probably do something like this: You could put this into your User model (whatever model you'd need to use it with) /**
* @param string|int|array|Role|Collection|\BackedEnum $roles
* @param int|array $teams
*/
function assignRolesToTeams($roles, $teams)
{
if (! app(PermissionRegistrar::class)->teams) {
return;
}
$teams = Arr::wrap($teams);
$team_id_to_be_restored = getPermissionsTeamId();
foreach ($teams as $team) {
setPermissionsTeamId($team);
$this->assignRole($roles);
}
setPermissionsTeamId($team_id_to_be_restored);
} When working on a proposal, consider what additional team-related functions would be needed too. |
Beta Was this translation helpful? Give feedback.
-
Hello,
On the doc, when you want to assign roles/permissions to a team it say :
The role/permission assignment and removal for teams are the same as without teams, but they take the global team_id which is set on login.
Ok that is cool, but what if you want assign a role to many teams or even many roles to many teams ?
I suggest something like this :
The first
assignRole
would generate the following entries :Beta Was this translation helpful? Give feedback.
All reactions