Laravel - Return json along with http status code

后端 未结 8 1891
北恋
北恋 2020-12-08 03:57

If I return an object:

return Response::json([
    \'hello\' => $value
]);

the status code will be 200. How can I change it to 201, with

8条回答
  •  春和景丽
    2020-12-08 04:15

    I prefer the response helper myself:

        return response()->json(['message' => 'Yup. This request succeeded.'], 200);
    

提交回复
热议问题