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 - Laravel Tutorial
From the course: Building a Website with Laravel, React.js, and Inertia
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
-
-
-
-
-
(Locked)
Introduction to Inertia.js1m 16s
-
(Locked)
Getting started with a new Inertia project1m 58s
-
(Locked)
Creating a Post resource2m 29s
-
(Locked)
Creating the Home and About pages2m 14s
-
Creating an Inertia navigation2m 6s
-
(Locked)
Changing the website title2m 4s
-
(Locked)
Displaying posts3m 4s
-
(Locked)
Creating posts4m 37s
-
(Locked)
Displaying a single post1m 29s
-
(Locked)
Updating posts1m 51s
-
(Locked)
Deleting posts1m 33s
-
(Locked)
Challenge: Show a flash message1m 2s
-
(Locked)
Solution: Show a flash message2m 59s
-
(Locked)
-