-
our text editor. Let's scroll down to the end of our template here, as we need to add in our confirm destroy dialogue.
-
Inside of here, we're going to say, are you sure you'd like to delete your, and then inside of a strong element, add in the destroy resource name, and we're going to label that with question
-
mark. This will inform users that all data associated with this course, including modules and lessons, will be deleted forever.
-
Whoops, did not mean to carry the strong tag all the way through there. That was supposed to end right there. As for our props for our confirmed destroy dialogue, we have our view model for the open
-
flag that we can set to our destroy is open. We can go ahead and title this dialogue, delete course with a question mark, and then send
-
the action href to slash courses, slash destroy resource ID, and then end our back there.
-
Now we need to provide ourselves a way to be able to open this outside of this component. So that's where the define expose comes in.
-
Once more, we'll add in one more function called on destroy that accepts in the course
-
that we want to delete of type course DTO, and this one's going to call our destroy value open method, passing that course in.
-
Then we just want to expose that outside of this component as destroy on destroy. Then inside of our courses page, just like we did with our edit, we can now on delete
-
handle the at click event, passing that to our actions, destroy, and then passing the specific course from the loop item in. Let's go ahead and jump back into our terminal now and create a new action.
-
So node ace make action inside of our courses directory called destroy course. All right, we can clear that out, jump back into our text editor, and let's go into that
-
destroy course action. This will accept in our organization of type organization, and then the ID that we want to delete.
-
Taking the organization and ID out of our handle method, we'll first want to grab the course.
-
We can await organization related courses, query where the ID matches the one that we want to delete, and then grab the first or fail.
-
Then we'll just go ahead and await course and delete it from the database, and we can return that course back just in case it's needed. All right, next, that takes us to our courses controller.
-
Let's go ahead and scroll down a little bit here and add in an async destroy method with params, response, and organization extracted out of our HTTP context.
-
For this one, all that we want to do is await destroy course, all the handle method, passing the ID from our params ID, as well as the organization.
-
Then we'll return response, redirect the user to our courses index page, and we're explicitly
-
redirecting there because we're also going to add this ability inside of the courses show page. If they delete the course, then they no longer have anything to show there, so we need to send them back to the index. Give that a save.
-
Jumping now into our web routes and adding a router, delete, slash, courses, slash, and
-
then an ID route parameter using the course controllers destroy method as courses.destroy. Okay, we should be able to give that a save.
-
Jump back into our browser now. I think we need to give that another refresh there. Then I'm going to go ahead and just add in a brand new course called delete me. All right. We have that added.
-
Let's go ahead and click our dropdown menu and hit delete. Delete course. Are you sure you'd like to delete your delete me course? I'm going to go ahead and hit delete there, and sure enough, it's now gone.