In this episode, we walk through the whole process of accepting a pending friend request in our app. To set the stage: Alex has already sent a friend request to Mabel, so now we're working on Mabel's side, letting her accept the request.
We start by writing a feature test for this functionality. The idea is to make sure that when Mabel accepts the friend request, the database updates accordingly—specifically, it should mark the friendship as "accepted." We set up the route using a PATCH request (which makes sense for updating an existing relationship), and create a new controller just for handling this logic.
Once the backend is set up (and our tests are passing!), we jump into updating the UI. We tweak the friends index view to show pending friend requests, add the email address for a bit more context, and set up a form with a button to actually accept the request. Since we're using a PATCH request, we use Laravel's method spoofing in the form.
After implementing everything, we check our app and confirm that once the accept button is clicked, both users are now listed as friends. As a little extra touch, we make sure the friends list also shows email addresses for consistency.
By the end of the episode, you've seen a full test-driven approach to updating the friends system with the ability to accept requests. Next up, we'll probably look at removing friends!