public function addRoles($role) { $user_role = new SysUserRole(); $user_role->admin_id = $this->id; $user_role->r_id = $role; return $user_role->save(); }
public function addUser($admin_id) { $user_role = new SysUserRole(); $user_role->admin_id = $admin_id; $user_role->r_id = $this->id; return $user_role->save(); }
public function addUserRole($id) { $roles = Input::get('roles', null); try { SysUserRole::clearUserRole($id); if (!empty($roles)) { $roles = explode(',', $roles); // delete current user role relation $admin = SysUser::find($id); foreach ($roles as $key => $role) { if (!$role) { continue; } $admin->addRoles($role); } } $re = Tools::reTrue('处理角色成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '处理角色失败:' . $e->getMessage()); } return Response::json($re); }
public function postRoleUser($id) { $users = Input::get('users', ''); try { SysUserRole::clearRoleUser($id); if (!empty($users)) { if (!is_array($users)) { $role = SysRole::find($id); if (empty($role)) { throw new Exception("没有找到请求的角色", 1); } $users = explode(',', $users); foreach ($users as $key => $user) { if (!$user) { continue; } $role->addUser($user); } } } $re = Tools::reTrue('设置用户成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '设置用户失败:' . $e->getMessage()); } return Response::json($re); }