laravel-friendships icon indicating copy to clipboard operation
laravel-friendships copied to clipboard

Problem when we Deny Friend Request and send another request

Open oza75 opened this issue 6 years ago • 0 comments

Hi, and thanks for this package! I got some troubles. When you deny a friend request and sent another request, the canBeFriend method always return true. I take a look on your code and the problem was in

    /**
     * @param Model $recipient
     *
     * @return \Hootlex\Friendships\Models\Friendship
     */
    public function getFriendship(Model $recipient)
    {
        return $this->findFriendship($recipient)->first();
    }

This methods return the first request that was sent but if a first was denied the canBeFriend doesn't take care of it and then it's return true even if another request was sent. I try to fix that by change the getFriendship method.

    /**
     * @param Model $recipient
     *
     * @return \Hootlex\Friendships\Models\Friendship
     */
    public function getFriendship(Model $recipient)
    {
        return $this->findFriendship($recipient)
            ->where('status', '<>', Status::DENIED)
            ->first();
    }

That solve my problem but i don't know if it cause another problem somewhere.

So this is the right way to solve this problem or there is another way

oza75 avatar Sep 09 '18 16:09 oza75