hootlex / laravel-friendships

This package gives Eloquent models the ability to manage their friendships.
MIT License
706 stars 151 forks source link

Problem when we Deny Friend Request and send another request #111

Open oza75 opened 5 years ago

oza75 commented 5 years ago

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