In this episode, we focus on solving the problem of duplicate friend requests in our app. First, we tidy up by removing any existing record for a friend request (just to keep things clean). Then, we talk about how to check if there's already a pending friend request to a user—no more sending endless requests to the same person!
We build a handy method right on the user model called hasPendingFriendRequestFor
. This neat little helper will check if you've already sent a friend request to someone, using Laravel's elegant relationship features.
With that set up, we put the check in our FriendStoreController so if a user tries to send a second request, nothing happens and they're kept right where they are—no duplicate database records!
But user experience matters, too. Over on the profile page, we update the UI so if you've already sent a friend request, you see a message letting you know you’re just waiting for the other person to accept (instead of being able to spam the button). We set things up nicely, wrapping the form in an auth check so only logged-in users see it.
To finish up, we start thinking about letting users cancel their pending requests, making some tweaks to the form and laying out the groundwork for cancellation functionality in the next steps. We round things off by mentioning we’ll reflect these updates on the friends page as well.
All in all, this episode is all about preventing duplicate requests and giving users a clearer, smoother experience when making friends!