Reputation: 8179
Laravel version: 5.5
I am trying to return custom http status code from the laravel controller. (Calling this url using jQuery Ajax $.get())
In my controller function I tried both the way mentioned bellow but it's not working.
This one returns error "Method setStatusCode does not exist."
return response()->setStatusCode(202);
This one not throwing error but returning 200 always.
$response = new Response();
$response->setStatusCode(202);
$response->header('custom', 555);
return $response;`
Upvotes: 2
Views: 7807
Reputation: 53
Let me present a few more methods of use. Maybe you are looking for something like this without json.
response(null)->setStatusCode(202);
response(null, 202);
Upvotes: 0
Reputation: 359
Use it like this:
return response()->json("response content", 202);
//or
return response()->make("response content", 202);
Check https://laravel.com/api/5.0/Illuminate/Routing/ResponseFactory.html for more detailed documentation.
Upvotes: 5