Introduce support to return 201 status code in Json Responses #291
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While refactoring our existing code from Laravel API resources to using Laravel Data, we noticed a lot of our tests were starting to fail, because we expect a
201 CREATED
response code when we are creating a new resource.I checked the Laravel codebase, and they return a 201 when
$model->wasRecentlyCreated()
equalstrue
.Obviously, the same check can not be done in this package, but I believe it would make sense to test for the request method, and if it is a POST request, we can have return the Json response with a 201 status code, which is what I implemented in this PR.
Obviously, in order to ensure backwards compatibility, I disabled this by default by adding a new config parameter that is y default set to false, but can be enabled in the config file, so this can be release as a minor and not a major.