In this episode, we're adding the ability to delete a site from our dashboard. We start by adding a simple "Delete Site" button in the UI, place it nicely with some styling, and then hook up the click event to call our new deleteSite
method.
When the button is clicked, we pop up a basic JavaScript confirm
dialog to check if the user really wants to delete the site. If they proceed, we trigger a delete request using Inertia.js, passing in the correct site ID from our props.
On the backend, we create a new controller (SiteDestroyController
) and set up the corresponding web route using Laravel's route model binding. In our controller, we ensure the user is authenticated, then simply delete the site record from the database. Because of our database constraints, deleting a site also removes any related endpoints and checks automatically (thanks, cascade deletes!).
After deletion, the user is redirected back to the dashboard or their next site. Finally, we add an authorization check using form requests and policies to make sure only the site owner can delete the site. We wrap up by testing everything out—create a new site, delete it, and make sure it all works smoothly.
By the end of this episode, we now have a fully functional way for users to remove their sites from the platform, with proper authorization and clean cascades in the database. 🚀