Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add Method to Query All Friendship Statuses #110

Open
AlwaysShreeKrishna opened this issue Jun 17, 2024 · 2 comments
Open

Comments

@AlwaysShreeKrishna
Copy link

AlwaysShreeKrishna commented Jun 17, 2024

Hello,

I would like to request a new feature for the library to include a method that allows querying friendships without filtering by a specific status. The current implementation only allows querying by a specific status, which limits the flexibility of the querying capabilities.
/**
* Get the query builder of the 'friend' model
*
* @param string $groupSlug
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getFriendsQueryBuilder($groupSlug = '')
{
$friendships = $this->findFriendships(Status::ACCEPTED, $groupSlug)->get(['sender_id', 'recipient_id']);
$recipients = $friendships->pluck('recipient_id')->all();
$senders = $friendships->pluck('sender_id')->all();

    return $this->where('id', '!=', $this->getKey())
                ->whereIn('id', array_merge($recipients, $senders));
}

Proposed Solution:
Here is an example of how the new method can be implemented:
/**
* Get the query builder of the 'friend' model
*
* @param string $status
* @param string $groupSlug
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getFriendsQueryBuilder(status = Status::ACCEPTED,$groupSlug = '')
{
$friendships = $this->findFriendships($status, $groupSlug)->get(['sender_id', 'recipient_id']);
$recipients = $friendships->pluck('recipient_id')->all();
$senders = $friendships->pluck('sender_id')->all();

    return $this->where('id', '!=', $this->getKey())
                ->whereIn('id', array_merge($recipients, $senders));
}
@mkwsra
Copy link
Member

mkwsra commented Jun 18, 2024

Sounds great, make it as PR and I will accept it immediately, (so you can take the credits :D)
Thanks Shree krishna

@AlwaysShreeKrishna
Copy link
Author

AlwaysShreeKrishna commented Jun 19, 2024

I have taken PR #111 please review and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants