From the course: Building RESTful APIs in Laravel

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

DELETE a petition

DELETE a petition

From the course: Building RESTful APIs in Laravel

Start my 1-month free trial

DELETE a petition

- [Instructor] The last method we need to test is the destroy method, which will take a specific resource and delete it. Let's create a new request, call it "delete a petition," and select the delete HTTP verb from the drop down. We we use the petitions variable and append the ID of the petition we want to delete. Let's say, ID number 25. Let's click send and see what happens. This time, the response we receive contains an empty body, and a status 204 no content. This is the status code we define in a destroy method. Let's go back to PHP storm, the petition controller, and change it to something else. Just to make sure that the status code will change in our response. I'm going to use the response class to return the status code. A fun code is 418, "I'm a teapot." This response status code is just a joke, and not really implemented in production. But it's a fun one to use in this scenario. Let's run the request again…

Contents