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
- [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
-
-
-
-
-
Using API resources to display all petitions6m 5s
-
(Locked)
Saving a new petition2m 24s
-
(Locked)
Displaying a specific petition2m 52s
-
(Locked)
Updating an existing petition2m 17s
-
(Locked)
Deleting a petition4m 27s
-
(Locked)
Challenge: Building the author resource1m 8s
-
(Locked)
Solution: Building the author resource2m 25s
-
-
-