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

Non-eloquent resource creation results in a 200 HTTP code #101

Closed
robinstraub opened this issue Jul 5, 2021 · 2 comments
Closed

Non-eloquent resource creation results in a 200 HTTP code #101

robinstraub opened this issue Jul 5, 2021 · 2 comments

Comments

@robinstraub
Copy link

robinstraub commented Jul 5, 2021

I am using some non-eloquent resources in my project.
When I POST new resouirces I get 200 codes instead of 201.
I did register a repository, implemented the CreatesResource contract and write a create() method implementation in my CrudResource.

Did I miss something ? Do you need a reproduction example ?

@lindyhopchris
Copy link
Contributor

Hi! No you haven't missed anything. At the moment the response classes detect whether the underlying model/non-Eloquent object was created during the current HTTP request. For non-Eloquent objects this means you need to implement this interface on the class: https://github.com/laravel-json-api/core/blob/develop/src/Contracts/Resources/Creatable.php

If you don't want to implement the interface, you'd need to use the created hook on the controller to return a DataResponse that calls the didCreate() helper method as per these docs: https://laraveljsonapi.io/docs/1.0/responses/#create-resource-response

That'll work for the current release. I think though I should update the create controller action so that it always calls didCreate as that would make sense for that controller action. I'll leave this issue open to remind me to make that change.

@robinstraub
Copy link
Author

Ok perfect, thanks for the wuick reply. I'll implement the interface in the meantime.

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

No branches or pull requests

2 participants