dimanche 19 mai 2019

update method is returning 200 OK error code. how can I specify returned error code when validation is failed

validation has been failed so it goes to else statement and it returns 200 OK error code. How can I return a right error code when update has been failed with redirect function?

 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);
        }
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire