Support the ongoing development of Laravel.io →
posted 3 years ago
Last updated 2 years ago.
0
moderator

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);
}
0

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)

Last updated 3 years ago.
0
moderator

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Oleg ochernyavskyi Joined 10 Dec 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.