From the course: Building RESTful APIs in Laravel

Unlock the full course today

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

Deleting a petition

Deleting a petition

From the course: Building RESTful APIs in Laravel

Start my 1-month free trial

Deleting a petition

- [Instructor] We are almost done with our petition control methods. The last method we need to implement is the destroy method. The destroy method will delete a single resource. Similarly to the update methods, when you implement authentication in your API you will need to check if the user is authenticated and authorized to delete a resource. But since we are not doing any authentication in this course let me just show you how you would simply delete a petition. Let's open our petition control file and scroll down to the destroy methods. We will take this petition and call the delete method on it and that's it, very easy. Next we have to return a JSON response. In the JSON response, the first parameter will be null. And the second parameter will be the status code in our case 204, no content. The reason we are returning null as the first parameter is because we are not returning anything in the body of the response as…

Contents