By default you get a 200 response code, you can change it by returning an response with a specific code.
// with an object
return new Illuminate\Http\Response('your cpntent', 201);
// Or with an helper
return \response('your content', 201);
// Or with the factory injected as depencency
public function register(ValidationRequest $request, Illuminate\Contracts\Routing\ResponseFactory $responseFactory)
{
$arr = ['email' => $request->input('email'), 'password' => $request->input('password')];
$this->userService->createUser($arr);
return $responseFactory->make('your content', 201);
}
Thanks for your answer. I have tried as example this variant: return \response('your content', 201); But I'm still getting response 200, any ideas? [https://drive.google.com/file/d/13LbRbASd6g8xQcfOpkOvtdK5fnxO9Kf_/view?usp=sharing](Postman response)
Hmm, do you have any middleware on that route that could change it? It sounds strange that you get a 200 while you define the 201 response code.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community