Laravel - Return json along with http status code

后端 未结 8 1907
北恋
北恋 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:06

    return response(['title' => trans('web.errors.duplicate_title')], 422); //Unprocessable Entity
    

    Hope my answer was helpful.

提交回复
热议问题