🔥 Quick Tip: Using HTTP Status Codes with Laravel API Resources
With Laravel 5.5 an awesome feature was added to the core: API Resources. If you have not done it already give it a try. As usual it is well explained in the documentation. For our API we needed one feature which is not documented: Custom Status Codes.
To get something from the API mostly
200 OK is the default status code, which is fine. When a new record is created successful, you want to use
201 Created and for updated records one would exepct a
202 Accepted .
But Laravel API Resources send
200 OK by default. If you want to change the response, try it this way:
If you don’t use different status codes, give it a try. It is just a basic info, which helps debugging requests a lot.