Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Return 201 in case of a Model just created. #21603

Closed

Conversation

mathieutu
Copy link
Contributor

Allow to do :

class UserController extends Controller
{
    public function store(UserStoreRequest $request)
    {
        return User::create($request->only(['email', 'password']));
    }

    // ...

@themsaid themsaid changed the title Return 201 in case of a Model just created. [5.5] Return 201 in case of a Model just created. Oct 10, 2017
@themsaid
Copy link
Member

themsaid commented Oct 10, 2017

I think this is a breaking change since people will start getting 201 instead of 200, some tests might fail and clients consuming the API might start complaining.

@mathieutu
Copy link
Contributor Author

Hum, you're right, I can understand that...
Actually I made that because I thought it was already like that, and when I tried it didn't works ^^".

Do you really think some people are returning a just created user with a 200 in a api ? 😱

@themsaid
Copy link
Member

themsaid commented Oct 10, 2017

the answer is YES :D I do . don't really care about the response code in many cases.

@edmandiesamonte
Copy link
Contributor

This PR actually makes sense. Though @themsaid is actually right, this is a breaking change.

Additional feedback is to extend this concern to Resources. There should be a consistency between the two - when returning a model and when returning a resource.

https://github.com/laravel/framework/blob/5.5/src/Illuminate/Http/Resources/Json/ResourceResponse.php#L113

@taylorotwell
Copy link
Member

taylorotwell commented Oct 10, 2017

I do like this change but yeah would prefer it on 5.6 (master branch).

@mathieutu
Copy link
Contributor Author

Ok I'll reopen it on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants