diff --git a/README.md b/README.md index 57926b4..23cc73d 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,11 @@ $user->getAllFriendships(); $user->getPendingFriendships(); ``` +#### Get a list of pending Requests +```php +$user->getPendingRequests(); +``` + #### Get a list of accepted Friendships ```php $user->getAcceptedFriendships(); diff --git a/src/Traits/Friendable.php b/src/Traits/Friendable.php index e19e7f0..bcee028 100755 --- a/src/Traits/Friendable.php +++ b/src/Traits/Friendable.php @@ -242,6 +242,17 @@ public function getPendingFriendships($groupSlug = '') return $this->findFriendships(Status::PENDING, $groupSlug)->get(); } + /** + * @return \Illuminate\Database\Eloquent\Collection|Friendship[] + * + * @param string $groupSlug + * + */ + public function getPendingRequests($groupSlug = '') + { + return $this->findPendingRequests(Status::PENDING, $groupSlug)->get(); + } + /** * @return \Illuminate\Database\Eloquent\Collection|Friendship[] * @@ -422,6 +433,29 @@ private function findFriendships($status = null, $groupSlug = '') return $query; } + /** + * @param $status + * @param string $groupSlug + * + * @return \Illuminate\Database\Eloquent\Collection + */ + private function findPendingRequests($status = null, $groupSlug = '') + { + + $query = Friendship::where(function ($query) { + $query->where(function ($q) { + $q->whereSender($this); + }); + })->whereGroup($this, $groupSlug); + + //if $status is passed, add where clause + if (!is_null($status)) { + $query->where('status', $status); + } + + return $query; + } + /** * Get the query builder of the 'friend' model *