验证失败,因此转到 else 语句并返回200 OK错误代码。当使用重定向功能更新失败时,如何返回正确的错误代码?
public function update(Request $request, $id)
{
$validator = $this->userService->update_validate($request->all(),$id);
if ($validator) {
try {
$user = $this->userService->updateUser($request, $id);
return response()->json($user, 200);
} catch (ModelNotFoundException $ex) {
throw $ex;
} catch (Exception $e) {
return response()->json(['message' => $e->getMessage()], 500);
}
} else {
return redirect()->back()
->withErrors($validator);
}
}
鸿蒙传说