From the course: Building a Website with Laravel, React.js, and Inertia

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Creating PostController show, update, and destroy methods

Creating PostController show, update, and destroy methods - Laravel Tutorial

From the course: Building a Website with Laravel, React.js, and Inertia

Creating PostController show, update, and destroy methods

- [Narrator] Let's zoom through the remaining methods in the PostController now. Show will display a single resource. The update method is very similar to the store method, so I'll copy/paste most of the code and just update the method call from create to update. I'll also copy the stored PostRequest and use the same code and update PostRequest. The updated request will be almost identical except for the unique rule on the title. We want the title to be unique, but only when we are creating a new post. Finally, the destroy method. We will simply run PostDelete. When we delete a resource, we need to return some sort of message to the user to make it obvious that the resource has been deleted. We are no longer returning a post resource, but a simple JSON response with a status code of 204, no content. This would be the typical response, but you can choose to return a different response. 200, success might make sense, 404, not found, or even 410, gone. Be as explicit as you can. Let's do…

Contents