In this episode, we tackle what should happen to your team memberships when you delete your account. Apps often give you the ability to delete your profile, and with our Breeze starter kit, that's no different. But if you're part of any teams, we definitely don't want to just delete those teams outright—after all, other users might still be in them!
So, what we want to do is simply detach yourself from all your teams when you delete your account. We'll do this by updating our user observer to handle the deleting
event, making sure the user is removed from any related teams before they're actually gone from the database.
We then write a quick test to confirm this works. The process involves attaching a couple of teams to a new user, deleting the user, and then asserting that all the entries relating to that user in the team_user
pivot table are, in fact, gone. We also handle some quirks, like making sure our user factory doesn't trigger the observer unnecessarily when creating the teams.
At the end of the day, this means when you delete your account, you'll quietly leave any teams you were in, without disrupting the teams themselves or the other people in them. Neat and tidy!