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

Updating an existing petition

From the course: Building RESTful APIs in Laravel

Start my 1-month free trial

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