/** * Attach Roles to a User. * * @param $user * @param $roleIds */ public function addRoles($user, $roleIds) { foreach ($roleIds as $id => $value) { $role = $this->roleRepository->findById($id); $user->attachRole($role); } }
public function postPermissionMatrix(Request $request) { $roles = $request->get('roles'); if ($roles) { foreach ($roles as $roleId => $permissions) { $this->role->updatePermissions($roleId, $permissions); } } return redirect()->back()->withSuccess("Permissions updated"); }
public function getDeleteRole($id) { // system roles should not get deleted if ($id == 1 || $id == 2) { Flash::warning('System roles cannot be deleted.'); return redirect()->back(); } // check for permission if (!Auth::user()->can('manage-role-perm')) { Flash::warning('You do not have permission to delete roles.'); return redirect()->back(); } $this->role->delete($id); Flash::success('Role was deleted'); return redirect()->back(); }