class CursorPaginator extends AbstractCursorPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, Jsonable, JsonSerializable, CursorPaginator

Traits

Properties

protected bool $hasMore

Indicates whether there are more items in the data source.

protected TValue> $items

All of the items being paginated.

from  AbstractCursorPaginator
protected int $perPage

The number of items to be shown per page.

from  AbstractCursorPaginator
protected string $path

The base path to assign to all URLs.

from  AbstractCursorPaginator
protected array<string, mixed> $query

The query parameters to add to all URLs.

from  AbstractCursorPaginator
protected string|null $fragment

The URL fragment to add to all URLs.

from  AbstractCursorPaginator
protected string $cursorName

The cursor string variable used to store the page.

from  AbstractCursorPaginator
protected Cursor|null $cursor

The current cursor.

from  AbstractCursorPaginator
protected array<int, string> $parameters

The paginator parameters for the cursor.

from  AbstractCursorPaginator
protected array<string, mixed> $options

The paginator options.

from  AbstractCursorPaginator
static protected Closure|null $currentCursorResolver

The current cursor resolver callback.

from  AbstractCursorPaginator

Methods

mixed
forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

mixed
forwardDecoratedCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object, returning $this if the forwarded call returned itself.

static never
throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

mixed
tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

from  Tappable
toResourceCollection(string|null $resourceClass = null)

Create a new resource collection instance for the given resource.

guessResourceCollection()

Guess the resource collection for the items.

string|null
resolveResourceFromAttribute(string $class)

Get the resource class from the class attribute.

string|null
resolveResourceCollectionFromAttribute(string $class)

Get the resource collection class from the class attribute.

render(string|null $view = null, array $data = [])

Render the paginator using the given view.

string
url(Cursor|null $cursor)

Get the URL for a given cursor.

string|null
previousPageUrl()

Get the URL for the previous page.

string|null
nextPageUrl()

The URL for the next page, or null.

Cursor|null
previousCursor()

Get the "cursor" that points to the previous set of items.

Cursor|null
nextCursor()

Get the "cursor" that points to the next set of items.

getCursorForItem(array|object $item, bool $isNext = true)

Get a cursor instance for the given item.

array
getParametersForItem(array|object $item)

Get the cursor parameters for a given object.

string|null
getPivotParameterForItem(Model $item, string $parameterName)

Get the cursor parameter value from a pivot model if applicable.

mixed
ensureParameterIsPrimitive(mixed $parameter)

Ensure the parameter is a primitive type.

fragment(string|null $fragment = null)

Get / set the URL fragment to be appended to URLs.

appends(array|string|null $key, string|null $value = null)

Add a set of query string values to the paginator.

appendArray(array $keys)

Add an array of query string values.

withQueryString()

Add all current query string values to the paginator.

addQuery(string $key, mixed $value)

Add a query string value to the paginator.

string
buildFragment()

Build the full fragment portion of a URL.

loadMorph(string $relation, array $relations)

Load a set of relationships onto the mixed relationship collection.

loadMorphCount(string $relation, array $relations)

Load a set of relationship counts onto the mixed relationship collection.

array
items()

Get the slice of items being paginated.

through(callable $callback)

Transform each item in the slice of items using a callback.

int
perPage()

Get the number of items shown per page.

Cursor|null
cursor()

Get the current cursor being paginated.

string
getCursorName()

Get the query string variable used to store the cursor.

setCursorName(string $name)

Set the query string variable used to store the cursor.

withPath(string $path)

Set the base path to assign to all URLs.

setPath(string $path)

Set the base path to assign to all URLs.

string|null
path()

Get the base path for paginator generated URLs.

static Cursor|null
resolveCurrentCursor(string $cursorName = 'cursor', Cursor|null $default = null)

Resolve the current cursor or return the default value.

static void
currentCursorResolver(Closure $resolver)

Set the current cursor resolver callback.

static mixed
viewFactory()

Get an instance of the view factory from the resolver.

static void
flushState()

Flush all static state.

getIterator()

Get an iterator for the items.

bool
isEmpty()

Determine if the list of items is empty.

bool
isNotEmpty()

Determine if the list of items is not empty.

int
count()

Get the number of items for the current page.

getCollection()

Get the paginator's underlying collection.

setCollection(Collection $collection)

Set the paginator's underlying collection.

array
getOptions()

Get the paginator options.

bool
offsetExists(TKey $key)

Determine if the given item exists.

mixed
offsetGet(TKey $key)

Get the item at the given offset.

void
offsetSet(null|TKey $key, TValue $value)

Set the item at the given offset.

void
offsetUnset(TKey $key)

Unset the item at the given key.

string
toHtml()

Render the contents of the paginator to HTML.

mixed
__call(string $method, array $parameters)

Make dynamic calls into the collection.

string
__toString()

Render the contents of the paginator when casting to a string.

__construct(mixed $items, int $perPage, Cursor|null $cursor = null, array $options = [])

Create a new paginator instance.

void
setItems(mixed $items)

Set the items for the paginator.

links(string|null $view = null, array $data = [])

Render the paginator using the given view.

bool
hasMorePages()

Determine if there are more items in the data source.

bool
hasPages()

Determine if there are enough items to split into multiple pages.

bool
onFirstPage()

Determine if the paginator is on the first page.

bool
onLastPage()

Determine if the paginator is on the last page.

array
toArray()

Get the instance as an array.

array
jsonSerialize()

Convert the object into something JSON serializable.

string
toJson(int $options = 0)

Convert the object to its JSON representation.

string
toPrettyJson(int $options = 0)

Convert the object to pretty print formatted JSON.

Details

in ForwardsCalls at line 22
protected mixed forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in ForwardsCalls at line 52
protected mixed forwardDecoratedCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object, returning $this if the forwarded call returned itself.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in ForwardsCalls at line 66
static protected never throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

never

Exceptions

BadMethodCallException

in Tappable at line 15
mixed tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

Parameters

callable|null $callback

Return Value

mixed

ResourceCollection toResourceCollection(string|null $resourceClass = null)

Create a new resource collection instance for the given resource.

Parameters

string|null $resourceClass

Return Value

ResourceCollection

Exceptions

Throwable

protected ResourceCollection guessResourceCollection()

Guess the resource collection for the items.

Return Value

ResourceCollection

Exceptions

Throwable

protected string|null resolveResourceFromAttribute(string $class)

Get the resource class from the class attribute.

Parameters

string $class

Return Value

string|null

protected string|null resolveResourceCollectionFromAttribute(string $class)

Get the resource collection class from the class attribute.

Parameters

string $class

Return Value

string|null

at line 90
Htmlable render(string|null $view = null, array $data = [])

Render the paginator using the given view.

Parameters

string|null $view
array $data

Return Value

Htmlable

string url(Cursor|null $cursor)

Get the URL for a given cursor.

Parameters

Cursor|null $cursor

Return Value

string

string|null previousPageUrl()

Get the URL for the previous page.

Return Value

string|null

string|null nextPageUrl()

The URL for the next page, or null.

Return Value

string|null

Cursor|null previousCursor()

Get the "cursor" that points to the previous set of items.

Return Value

Cursor|null

Cursor|null nextCursor()

Get the "cursor" that points to the next set of items.

Return Value

Cursor|null

Cursor getCursorForItem(array|object $item, bool $isNext = true)

Get a cursor instance for the given item.

Parameters

array|object $item
bool $isNext

Return Value

Cursor

array getParametersForItem(array|object $item)

Get the cursor parameters for a given object.

Parameters

array|object $item

Return Value

array

Exceptions

Exception

protected string|null getPivotParameterForItem(Model $item, string $parameterName)

Get the cursor parameter value from a pivot model if applicable.

Parameters

Model $item
string $parameterName

Return Value

string|null

protected mixed ensureParameterIsPrimitive(mixed $parameter)

Ensure the parameter is a primitive type.

This can resolve issues that arise the developer uses a value object for an attribute.

Parameters

mixed $parameter

Return Value

mixed

AbstractCursorPaginator|string|null fragment(string|null $fragment = null)

Get / set the URL fragment to be appended to URLs.

Parameters

string|null $fragment

Return Value

AbstractCursorPaginator|string|null

AbstractCursorPaginator appends(array|string|null $key, string|null $value = null)

Add a set of query string values to the paginator.

Parameters

array|string|null $key
string|null $value

Return Value

AbstractCursorPaginator

protected AbstractCursorPaginator appendArray(array $keys)

Add an array of query string values.

Parameters

array $keys

Return Value

AbstractCursorPaginator

AbstractCursorPaginator withQueryString()

Add all current query string values to the paginator.

protected AbstractCursorPaginator addQuery(string $key, mixed $value)

Add a query string value to the paginator.

Parameters

string $key
mixed $value

Return Value

AbstractCursorPaginator

protected string buildFragment()

Build the full fragment portion of a URL.

Return Value

string

AbstractCursorPaginator loadMorph(string $relation, array $relations)

Load a set of relationships onto the mixed relationship collection.

Parameters

string $relation
array $relations

Return Value

AbstractCursorPaginator

AbstractCursorPaginator loadMorphCount(string $relation, array $relations)

Load a set of relationship counts onto the mixed relationship collection.

Parameters

string $relation
array $relations

Return Value

AbstractCursorPaginator

array items()

Get the slice of items being paginated.

Return Value

array

AbstractCursorPaginator through(callable $callback)

Transform each item in the slice of items using a callback.

Parameters

callable $callback

Return Value

AbstractCursorPaginator

int perPage()

Get the number of items shown per page.

Return Value

int

Cursor|null cursor()

Get the current cursor being paginated.

Return Value

Cursor|null

string getCursorName()

Get the query string variable used to store the cursor.

Return Value

string

AbstractCursorPaginator setCursorName(string $name)

Set the query string variable used to store the cursor.

Parameters

string $name

Return Value

AbstractCursorPaginator

AbstractCursorPaginator withPath(string $path)

Set the base path to assign to all URLs.

Parameters

string $path

Return Value

AbstractCursorPaginator

AbstractCursorPaginator setPath(string $path)

Set the base path to assign to all URLs.

Parameters

string $path

Return Value

AbstractCursorPaginator

string|null path()

Get the base path for paginator generated URLs.

Return Value

string|null

static Cursor|null resolveCurrentCursor(string $cursorName = 'cursor', Cursor|null $default = null)

Resolve the current cursor or return the default value.

Parameters

string $cursorName
Cursor|null $default

Return Value

Cursor|null

static void currentCursorResolver(Closure $resolver)

Set the current cursor resolver callback.

Boot-only. The resolver persists in a static property for the worker lifetime and runs on every subsequent cursor-paginator's cursor lookup.

Parameters

Closure $resolver

Return Value

void

static mixed viewFactory()

Get an instance of the view factory from the resolver.

Return Value

mixed

static void flushState()

Flush all static state.

Return Value

void

Traversable getIterator()

Get an iterator for the items.

Return Value

Traversable

bool isEmpty()

Determine if the list of items is empty.

Return Value

bool

bool isNotEmpty()

Determine if the list of items is not empty.

Return Value

bool

int count()

Get the number of items for the current page.

Return Value

int

Collection getCollection()

Get the paginator's underlying collection.

Return Value

Collection

AbstractCursorPaginator setCollection(Collection $collection)

Set the paginator's underlying collection.

Parameters

Collection $collection

Return Value

AbstractCursorPaginator

array getOptions()

Get the paginator options.

Return Value

array

bool offsetExists(TKey $key)

Determine if the given item exists.

Parameters

TKey $key

Return Value

bool

mixed offsetGet(TKey $key)

Get the item at the given offset.

Parameters

TKey $key

Return Value

mixed

void offsetSet(null|TKey $key, TValue $value)

Set the item at the given offset.

Parameters

null|TKey $key
TValue $value

Return Value

void

void offsetUnset(TKey $key)

Unset the item at the given key.

Parameters

TKey $key

Return Value

void

string toHtml()

Render the contents of the paginator to HTML.

Return Value

string

mixed __call(string $method, array $parameters)

Make dynamic calls into the collection.

Parameters

string $method
array $parameters

Return Value

mixed

string __toString()

Render the contents of the paginator when casting to a string.

Return Value

string

at line 42
__construct(mixed $items, int $perPage, Cursor|null $cursor = null, array $options = [])

Create a new paginator instance.

Parameters

mixed $items
int $perPage
Cursor|null $cursor
array $options

(path, query, fragment, pageName)

at line 62
protected void setItems(mixed $items)

Set the items for the paginator.

Parameters

mixed $items

Return Value

void

Render the paginator using the given view.

Parameters

string|null $view
array $data

Return Value

Htmlable

at line 100
bool hasMorePages()

Determine if there are more items in the data source.

Return Value

bool

at line 110
bool hasPages()

Determine if there are enough items to split into multiple pages.

Return Value

bool

at line 118
bool onFirstPage()

Determine if the paginator is on the first page.

Return Value

bool

at line 126
bool onLastPage()

Determine if the paginator is on the last page.

Return Value

bool

at line 136
array toArray()

Get the instance as an array.

Return Value

array

at line 154
array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

at line 162
string toJson(int $options = 0)

Convert the object to its JSON representation.

Parameters

int $options

Return Value

string

at line 170
string toPrettyJson(int $options = 0)

Convert the object to pretty print formatted JSON.

Parameters

int $options

Return Value

string