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.

Deleting posts

Deleting posts

- [Instructor] Let's delete a post now. On our button in the index.jsx file, we will add an on-click event that will call a delete function where we will pass the post ID. Part of this on-click event will be asking the user if they really want to delete this post. If the user says yes, the delete function will be called. Now let's create a delete function that will code the post or destroy route. You might wonder why we are not using the use form element like we did when we created a post. We could do that, but it's not necessary in this case because we are not sending any payload to the control method like we did when we created or updated the post, just the post ID. For this reason, we will use Inertia's router instead. Let's import the router here at the top. Now let's create the destroy method in the controller now. All we need to do is to delete the post and redirect back to the homepage. That's our delete functionality done. Let's test it out in the browser. I'll try to delete…

Contents