From the course: Building a Website with Laravel, React.js, and Inertia
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Deleting a post - Laravel Tutorial
From the course: Building a Website with Laravel, React.js, and Inertia
Deleting a post
- [Instructor] The final piece of functionality we will implement is deleting posts. We already have a button for it that we will use. Currently, it doesn't do anything at all, so let's add an on click handler. That will trigger a handle delete post function, which will send a delete request with Axios. Let's build it together. In the post index component. Let's add an open function to the button that will call a handle delete post method. We'll pass in the post ID. Okay, onto the handle delete post method. I'll paste the code in and we will go over it together again. In here, we first ask the user if they really want to delete the post. We implement a simple confirmation alert to save time, but you could pull a confirmation module instead. Then we make a delete request with Axios to the API endpoint and pass in the post ID. Finally, we update the local state by removing the deleted post. All this disrupt inside a try-catch block to catch any potential errors. Let's try it out. I'm…
Contents
-
-
-
-
React and Laravel setup3m 32s
-
(Locked)
Creating the Home and About pages1m 52s
-
(Locked)
Creating website navigation3m 24s
-
(Locked)
Displaying posts on a website2m 10s
-
(Locked)
Refactoring to components1m 52s
-
(Locked)
Fetching posts from Laravel API2m 22s
-
(Locked)
Creating a new post3m 43s
-
(Locked)
Updating a post2m 40s
-
(Locked)
Deleting a post1m 42s
-
(Locked)
Challenge: Show individual post page56s
-
(Locked)
Solution: Show individual post page2m 4s
-
-
-