Skip to content

Commit

Permalink
feat: add cursorPaginate() support (larastan#1198)
Browse files Browse the repository at this point in the history
Co-authored-by: Viktor Szépe <[email protected]>
  • Loading branch information
BramVanBerkel and szepeviktor authored Mar 24, 2022
1 parent ceb29d7 commit fad8e61
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

* fix: updated `composer/pcre` to new PHP relevant version
* feat: add support for the `foreignId` column in migrations
* feat: add support for the `cursorPaginate()` paginator

## [2.1.0] - 2022-03-04

Expand Down
7 changes: 7 additions & 0 deletions stubs/Contracts/Pagination.stub
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ interface Paginator
*/
interface LengthAwarePaginator extends Paginator
{}

/**
* @mixin \Illuminate\Support\Collection
* @mixin \Illuminate\Pagination\CursorPaginator
*/
interface CursorPaginator extends Paginator
{}
11 changes: 11 additions & 0 deletions stubs/EloquentBuilder.stub
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,17 @@ class Builder
* @return \Illuminate\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null);

/**
* Paginate the given query into a cursor paginator.
*
* @param int|null $perPage
* @param array<array-key, mixed> $columns
* @param string $cursorName
* @param \Illuminate\Pagination\Cursor|string|null $cursor
* @return \Illuminate\Pagination\CursorPaginator
*/
public function cursorPaginate($perPage = null, $columns = ['*'], $cursorName = 'cursor', $cursor = null);
}

class Scope {}
Expand Down
14 changes: 14 additions & 0 deletions stubs/Pagination.stub
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ class Paginator extends AbstractPaginator implements \Illuminate\Contracts\Suppo
*/
class LengthAwarePaginator extends AbstractPaginator implements \Illuminate\Contracts\Support\Arrayable, \ArrayAccess, \Countable, \IteratorAggregate, \Illuminate\Contracts\Support\Jsonable, \JsonSerializable, \Illuminate\Contracts\Pagination\LengthAwarePaginator
{}

/**
* @implements \ArrayAccess<mixed, mixed>
* @implements \IteratorAggregate<mixed, mixed>
* @implements \Illuminate\Contracts\Support\Arrayable<array-key, mixed>
*/
class CursorPaginator extends AbstractPaginator implements \Illuminate\Contracts\Support\Arrayable, \ArrayAccess, \Countable, \IteratorAggregate, \Illuminate\Contracts\Support\Jsonable, \JsonSerializable, \Illuminate\Contracts\Pagination\CursorPaginator
{}

/**
* @implements \Illuminate\Contracts\Support\Arrayable<array-key, mixed>
*/
class Cursor implements \Illuminate\Contracts\Support\Arrayable
{}
1 change: 1 addition & 0 deletions tests/Type/data/paginator-extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

assertType('array', User::paginate()->all());
assertType('array', User::simplePaginate()->all());
assertType('array', User::cursorPaginate()->all());

0 comments on commit fad8e61

Please sign in to comment.