If I return an object:
return Response::json([
\'hello\' => $value
]);
the status code will be 200. How can I change it to 201, with
This is how I do it in Laravel 5
return Response::json(['hello' => $value],201);
Or using a helper function:
return response()->json(['hello' => $value], 201);
There are multiple ways
return \Response::json(['hello' => $value], STATUS_CODE);
return response()->json(['hello' => $value], STATUS_CODE);
where STATUS_CODE is your HTTP status code you want to send. Both are identical.
if you are using Eloquent model, then simple return will also be auto converted in JSON by default like,
return User::all();