Skip to content

Commit 16151fb

Browse files
authored
Merge pull request #74 from agus24/master
add cursor paginate support to `getFriends` and `getOrPaginate`
2 parents 25b283e + a669dc2 commit 16151fb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Traits/Friendable.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ public function getFriendRequests()
318318
*
319319
* @return \Illuminate\Database\Eloquent\Collection
320320
*/
321-
public function getFriends($perPage = 0, $groupSlug = '', array $fields = ['*'])
321+
public function getFriends($perPage = 0, $groupSlug = '', array $fields = ['*'], bool $cursor = false)
322322
{
323-
return $this->getOrPaginate($this->getFriendsQueryBuilder($groupSlug), $perPage, $fields);
323+
return $this->getOrPaginate($this->getFriendsQueryBuilder($groupSlug), $perPage, $fields, $cursor);
324324
}
325325

326326
/**
@@ -552,12 +552,16 @@ public function groups()
552552
return $this->morphMany($friendshipGroupsModelName, 'friend');
553553
}
554554

555-
protected function getOrPaginate($builder, $perPage, array $fields = ['*'])
555+
protected function getOrPaginate($builder, $perPage, array $fields = ['*'], bool $cursor = false)
556556
{
557557
if ($perPage == 0) {
558558
return $builder->get($fields);
559559
}
560560

561+
if ($cursor) {
562+
return $builder->cursorPaginate($perPage, $fields);
563+
}
564+
561565
return $builder->paginate($perPage, $fields);
562566
}
563567
}

0 commit comments

Comments
 (0)