Skip to content

Commit

Permalink
Delete a user
Browse files Browse the repository at this point in the history
  • Loading branch information
Saodus committed Nov 7, 2024
1 parent eee25b8 commit 66f8897
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
30 changes: 22 additions & 8 deletions app/Http/Controllers/FriendshipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.');
}
}
18 changes: 12 additions & 6 deletions resources/views/friendships/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@
</span>
<div class="flex space-x-2">
<!-- Boutons d'action en icônes -->
<button>
<img src="{{ asset('source/assets/images/message_friend_icon.png') }}" alt="Message" class="h-10 w-10">
</button>
<button>
<img src="{{ asset('source/assets/images/delete_friend_icon.png') }}" alt="Supprimer" class="h-10 w-10">
</button>

<button>
<img src="{{ asset('source/assets/images/message_friend_icon.png') }}" alt="Message" class="h-10 w-10">
</button>

<form action="{{ route('friends.destroy', ['friend' => $friend->user_id == Auth::id() ? $friend->friend->id : $friend->user->id]) }}" method="POST" onsubmit="return confirm('Are you sure you want to remove this friend?');">
@csrf
@method('DELETE')
<button type="submit">
<img src="{{ asset('source/assets/images/delete_friend_icon.png') }}" alt="Supprimer" class="h-10 w-10">
</button>
</form>
</div>
</div>
@endforeach
Expand Down

0 comments on commit 66f8897

Please sign in to comment.