diff --git a/app/Http/Controllers/FriendshipsController.php b/app/Http/Controllers/FriendshipsController.php index 3217d2f..747dbb6 100644 --- a/app/Http/Controllers/FriendshipsController.php +++ b/app/Http/Controllers/FriendshipsController.php @@ -37,14 +37,14 @@ public function create() public function pending() { $pendingRequestsFromFriends = Friendship::where('friend_id', Auth::id()) - ->where('status', 'pending') - ->with('user', 'friend') - ->get(); + ->where('status', 'pending') + ->with('user', 'friend') + ->get(); $pendingRequestsFromUser = Friendship::where('user_id', Auth::id()) - ->where('status', 'pending') - ->with(['user', 'friend']) - ->get(); + ->where('status', 'pending') + ->with(['user', 'friend']) + ->get(); $pendingRequests = $pendingRequestsFromFriends->merge($pendingRequestsFromUser); @@ -111,7 +111,21 @@ public function decline(Request $request, $friendship_id) return back()->with('error', 'Could not decline the friend request.'); } - public function removeFriend(Request $request) + public function destroy($friend) { - } + $friendship = Friendship::where(function ($query) use ($friend) { + $query->where('user_id', Auth::id()) + ->where('friend_id', $friend); + })->orWhere(function ($query) use ($friend) { + $query->where('user_id', $friend) + ->where('friend_id', Auth::id()); + })->first(); + + if ($friendship) { + $friendship->delete(); + return back()->with('success', 'Friend removed successfully!'); + } + + return back()->with('error', 'Could not find the friend to remove.'); + } } diff --git a/resources/views/friendships/index.blade.php b/resources/views/friendships/index.blade.php index 5169b58..034e872 100644 --- a/resources/views/friendships/index.blade.php +++ b/resources/views/friendships/index.blade.php @@ -26,12 +26,18 @@