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
814 stars 72 forks source link

getPendingsCount() is not in the Friendable trait #70

Closed sarik-k closed 2 years ago

sarik-k commented 3 years ago

Documentation says its there but its not.

mkwsra commented 3 years ago

Thanks a lot for reporting this, you are totally right, please edit the file src/Traits/Friendable.php

And add this function to it:


    /**
     * Get the number of pending requests
     *
     * @param  string  $groupSlug
     *
     * @return integer
     */
    public function getPendingsCount($groupSlug = '')
    {
        $friendsCount = $this->findFriendships(Status::PENDING, $groupSlug)->count();

        return $friendsCount;
    }

And I will be adding this function to the library and make a new release soon :) Thanks again for your help

sarik-k commented 3 years ago

You're welcome :)

Seems like it calculates for both Incoming and Outgoing requests. I only need the former - how many pending friend requests a user has.

Doing this in my controller for now:

$count = $request->user()->getFriendRequests()->count();
mkwsra commented 3 years ago

Awesome, you are already doing it correctly!

And thank you so much for your star, much appreciated 🙏