In this episode, we're tackling the final piece of our friend system: deleting a friend. The process is really similar to what we've already done for other actions like accepting or sending friend requests.
We start off by following our usual test-driven workflow—writing a test to delete a friend (we call it FriendDestroyTest
). To speed things up, we copy most of the logic from our patch (update) test, adjust it for deletion, and temporarily skip it until we're ready to implement the backend.
Next, we hook up a new controller (FriendDestroyController
) in our routes to handle delete requests. With a bit of copy-pasting, we get the basic setup done, including adding the necessary middleware.
Then we move on to the logic itself—using the structure we've already built, we just call our method to remove a friend and redirect the user. Once that's done, we revisit the test, unskip it, and verify that deleting a friend works flawlessly—the test goes green!
To finish up, we add a 'remove friend' button in our frontend template. Now users can actually delete friends from their list, and the app updates just as you'd expect.
That's pretty much it for the friend system! In the next episodes, we'll move on to working on our feed.