Deleting Tours: Implementing Soft-Deletion

Let's provide the users with an option to delete tours.

Creating a form for deleting tours

We are done with the create, update, and list part. One of the problems is that the list of tours will keep growing forever. There is no way to delete tours, except by manually removing them from our “database”. This is actually a more common solution than you might think. But in our case, we would like to offer a more user-friendly solution: a “Delete” action next to the “Edit” link we already have.

It shouldn’t be a link, though, because a link produces a GET request. A GET request is supposed to be a safe request that won’t produce any side-effects. It will only show data, not change it. When you want to do a delete operation, you should therefore do that with a POST request. A link can’t let the browser make a POST request, but a form can. So let’s create a minimalistic form for it in the “Actions” cell of the tours table in list-tours.php:

Get hands-on with 1400+ tech skills courses.