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.
Updating an existing petition
From the course: Building RESTful APIs in Laravel
Updating an existing petition
- [Instructor] Updating an existing petition will be very similar to creating a new one. But instead of using post HTTP method, we will be using either PUT or PATCH. PUT and PATCH are very similar in what they do. Both methods update an existing resource but PUT replaces the entire resource while PATCH applies only partial update to the resource. When using the PUT method, you need to send the entire resource. And if the resource doesn't already exist, it will be created. In this way, PUT works similar to post. As for PATCH you only need to send the data that you are updating, not the whole resource. Laravel will accept either a PUT or a PATCH method when our user wants to update a resource. Let's complete our update method now. Let's open our petition controller. We need to call the update method on the petition. Paste in the fields we want to update from the request, and then return a new petition resource. So…
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
-
-
-