Skip to content

Commit

Permalink
Merge pull request #123 from svenvanhees/attach-roles-across-guards
Browse files Browse the repository at this point in the history
Map and assign roles with different guards.
  • Loading branch information
vyuldashev authored Mar 30, 2020
2 parents f3bf61f + 12775af commit def3090
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/RoleBooleanGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
return;
}

$values = collect(json_decode($request[$requestAttribute], true))
$model->roles()->detach();

collect(json_decode($request[$requestAttribute], true))
->filter(static function (bool $value) {
return $value;
})
->keys()
->toArray();
->map(static function ($roleName) use ($model) {
$roleClass = app(PermissionRegistrar::class)->getRoleClass();
$role = $roleClass::where('name', $roleName)->first();
$model->assignRole($role);

$model->syncRoles($values);
return $roleName;
});
}
}

0 comments on commit def3090

Please sign in to comment.