-
Hej. I set up a new SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'team_id' cannot be null (SQL: insert into `model_has_roles` (`model_id`, `model_type`, `role_id`, `team_id`) values (1, App\Models\User, 1, ?)) Since I did not find any open or closed issues on this: Do I miss something? Shouldn't we are able to omit Best |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Automatic Global Role SuperAdminGlobal roles can be assigned to different teams, and as the primary key of the relationship this is required, If you have a global user, when you register a new team you must assign it the global default role(SuperAdmin) by created event , example on your team model public static function boot(){
parent::boot();
// here assign this team to a global user with global default role
self::created(function($teamModel){
// get session team_id to restore it later (maybe optional)
$session_team_id = getPermissionsTeamId();
setPermissionsTeamId($teamModel->your_team_id);
User::find('user_super_admin_id')->assignRole('SuperAdminGlobalExample')
setPermissionsTeamId($session_team_id);
}
}); Working on sessionFirst, you must register the id of the team that you are going to use on the session, look at the documentation here, so, on you middleware you needs //NOTE: this can be on the session middleware or other,
// but always before starting to use this package like `$user->hasRoles('role');`
setPermissionsTeamId(session('your_team_id')); Or, if you are going to assign roles to a different team than the one in the session, you must first put the desired team with the same function(as in the first example) setPermissionsTeamId($teamModel->your_team_id); |
Beta Was this translation helpful? Give feedback.
Automatic Global Role SuperAdmin
Global roles can be assigned to different teams, and as the primary key of the relationship this is required, If you have a global user, when you register a new team you must assign it the global default role(SuperAdmin) by created event , example on your team model