multicaret / laravel-acquaintances

This package gives Eloquent models the ability to manage friendships (with groups), followships along with Likes, favorites..etc.
https://laravel-news.com/manage-friendships-likes-and-more-with-the-acquaintances-laravel-package
MIT License
808 stars 72 forks source link

If the first friendship request is denied, then unlimited duplicate entries can appear in the friendship table #84

Open spinalwiz opened 2 years ago

spinalwiz commented 2 years ago

To recreate: Add a friend and then deny that friend request.

Re-add that friend multiple times and you will see multiple entries in the friendship table like this:

image

Cause: This is because \Multicaret\Acquaintances\Traits\Friendable::getFriendship() returns the first() match which will always be the entry with status == 'denied' which means \Multicaret\Acquaintances\Traits\Friendable::canBefriend() will always return true

Potential Fix: In \Multicaret\Acquaintances\Traits\Friendable::getFriendship() add an ->orderBy('created_at' , 'desc') (or updated_at) to get the most recent entry

Or if the intention is to have no duplicate entries in the friendship table then will need to change \Multicaret\Acquaintances\Traits\Friendable::befriend() to an upsert

younus93 commented 2 years ago

This was my initial observation while using this package. I am overcoming this by deleting the friend request when the request is denied.

francoism90 commented 1 year ago

@spinalwiz Could you please send a PR? If this is a bug, someone else will probably have it else well.

Chlemdel commented 1 year ago

This was my initial observation while using this package. I am overcoming this by deleting the friend request when the request is denied.

What method are you using to delete the requests?