public function deleteRole(Request $request) { $data = $request->all(); DB::beginTransaction(); try { UserRoleRight::where(['ROLE_ID' => $data['ID']])->delete(); UserUserRole::where(['ROLE_ID' => $data['ID']])->delete(); UserRole::where(['ID' => $data['ID']])->delete(); } catch (\Exception $e) { DB::rollback(); } DB::commit(); $userRole = UserRole::where(['ACTIVE' => 1])->get(['ID', 'NAME']); return response()->json(array('userRole' => $userRole)); }
public function hasRole($roleCode) { if ($this->ID) { $user_user_role = UserUserRole::getTableName(); $user_role = UserRole::getTableName(); $rows = UserUserRole::join($user_role, "{$user_user_role}.ROLE_ID", '=', "{$user_role}.ID")->where([$user_role . ".CODE" => $roleCode, $user_user_role . ".USER_ID" => $this->ID])->select($user_role . ".CODE")->distinct()->get(); if (count($rows) > 0) { return true; } else { return false; } } return false; }