Laravel: custom http status code not working

2449 views php

Laravel version: 5.5

I am trying to return custom http status code from the laravel controller.

In my controller function I tried both the way mentioned bellow but it's not working.

  1. This one returns error "Method setStatusCode does not exist."

    return response()->setStatusCode(202);
  2. This one not throwing error but returning 200 always.

    $response = new Response();
    $response->header('custom', 555);
    return $response;`

answered question

2 Answers


Use it like this:

return response()->json("response content", 202);
return response()->make("response content", 202);

Check for more detailed documentation.

posted this

You can use return Response::json(['hello' => $value],201);

posted this

Have an answer?


Please login first before posting an answer.