input('id'); $oldPassword = $request->input('old_password'); $newPassword = $request->input('new_password'); $user = DB::table('user')->where('id', $id)->first(); if ($user && $user->password === $oldPassword) { // The old password matches, so update the password DB::table('user')->where('id', $id)->update([ 'password' => $newPassword, ]); $updatedUser = DB::table('user')->where('id', $id)->first(); $response = array( 'success' => true, 'message' => 'Password telah diperbarui', 'id' => $updatedUser->id, 'kode' => $updatedUser->kode, 'password' => $updatedUser->password, 'nama' => $updatedUser->nama, 'no_telp' => $updatedUser->no_telp, ); return response()->json($response); } else { return "Invalid old password"; } } }