public function setPermissions($id, Request $request)
{
Laralum::permissionToAccess('laralum.roles.access');
# Check permissions
Laralum::permissionToAccess('laralum.roles.permissions');
# Find the role
$role = Laralum::role('id', $id);
if (!$role->allow_editing and !Laralum::loggedInuser()->su) {
abort(403, trans('laralum.error_editing_disabled'));
}
# All permissions
$permissions = Laralum::permissions();
# Edit the permission
foreach ($permissions as $perm) {
# Check for su
$modify = true;
if ($role->su) {
if ($perm->su) {
$modify = false;
}
}
if (!$perm->assignable and !Laralum::loggedInUser()->su) {
$modify = false;
}
if ($modify) {
if ($request->input($perm->id)) {
# The admin selected that permission
# Check if the relation existed
if ($this->checkPerm($perm->id, $role->id)) {
# The role had already that permission
} else {
# The role did not have that permission, so we need to add it
$this->addPerm($perm->id, $role->id);
}
} else {
# The admin did not select that permission
# Check if the relation existed
if ($this->checkPerm($perm->id, $role->id)) {
# The role had this permission, so we need to delete it
$this->deletePerm($perm->id, $role->id);
} else {
# The role did not exist and nothing need to be done
}
}
}
}
# Return a redirect
return redirect()->route('Laralum::roles')->with('success', trans('laralum.msg_role_perms_updated'));
}