abstract class AbstractPaginator implements CanBeEscapedWhenCastToString, Htmlable, Stringable mixin TKey,

Traits

Properties

protected TValue> $items

All of the items being paginated.

protected int $perPage

The number of items to be shown per page.

protected int $currentPage

The current page being "viewed".

protected string $path

The base path to assign to all URLs.

protected array<string, mixed> $query

The query parameters to add to all URLs.

protected string|null $fragment

The URL fragment to add to all URLs.

protected string $pageName

The query string variable used to store the page.

protected bool $escapeWhenCastingToString

Indicates that the paginator's string representation should be escaped when __toString is invoked.

int $onEachSide

The number of links to display on each side of current page link.

protected array<string, mixed> $options

The paginator options.

static protected Closure|null $currentPathResolver

The current path resolver callback.

static protected Closure|null $currentPageResolver

The current page resolver callback.

static protected Closure|null $queryStringResolver

The query string resolver callback.

static protected Closure|null $viewFactoryResolver

The view factory resolver callback.

static string $defaultView

The default pagination view.

static string $defaultSimpleView

The default "simple" pagination view.

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.

bool
hasMorePages()

Determine if there are more items in the data source.

bool
isValidPageNumber(int $page)

Determine if the given value is a valid page number.

string|null
previousPageUrl()

Get the URL for the previous page.

array
getUrlRange(int $start, int $end)

Create a range of pagination URLs.

string
url(int $page)

Get the URL for a given page number.

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

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

appends(array|string|null $key, array|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.

int|null
firstItem()

Get the number of the first item in the slice.

int|null
lastItem()

Get the number of the last item in the slice.

through(callable $callback)

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

int
perPage()

Get the number of items shown per page.

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.

int
currentPage()

Get the current page.

string
getPageName()

Get the query string variable used to store the page.

setPageName(string $name)

Set the query string variable used to store the page.

withPath(string $path)

Set the base path to assign to all URLs.

setPath(string $path)

Set the base path to assign to all URLs.

onEachSide(int $count)

Set the number of links to display on each side of current page link.

string|null
path()

Get the base path for paginator generated URLs.

static string
resolveCurrentPath(string $default = '/')

Resolve the current request path or return the default value.

static void
currentPathResolver(Closure $resolver)

Set the current request path resolver callback.

static int
resolveCurrentPage(string $pageName = 'page', int $default = 1)

Resolve the current page or return the default value.

static void
currentPageResolver(Closure $resolver)

Set the current page resolver callback.

static string|array|null
resolveQueryString(string|array|null $default = null)

Resolve the query string or return the default value.

static void
queryStringResolver(Closure $resolver)

Set with query string resolver callback.

static mixed
viewFactory()

Get an instance of the view factory from the resolver.

static void
viewFactoryResolver(Closure $resolver)

Set the view factory resolver callback.

static void
defaultView(string $view)

Set the default pagination view.

static void
defaultSimpleView(string $view)

Set the default "simple" pagination view.

static void
useTailwind()

Indicate that Tailwind styling should be used for generated links.

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.

escapeWhenCastingToString(bool $escape = true)

Indicate that the paginator's string representation should be escaped when __toString is invoked.

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 36
abstract Htmlable render(string|null $view = null, array $data = [])

Render the paginator using the given view.

Parameters

string|null $view
array $data

Return Value

Htmlable

at line 41
abstract bool hasMorePages()

Determine if there are more items in the data source.

Return Value

bool

at line 132
protected bool isValidPageNumber(int $page)

Determine if the given value is a valid page number.

Parameters

int $page

Return Value

bool

at line 140
string|null previousPageUrl()

Get the URL for the previous page.

Return Value

string|null

at line 154
array getUrlRange(int $start, int $end)

Create a range of pagination URLs.

Parameters

int $start
int $end

Return Value

array

at line 164
string url(int $page)

Get the URL for a given page number.

Parameters

int $page

Return Value

string

at line 190
AbstractPaginator|string|null fragment(string|null $fragment = null)

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

Parameters

string|null $fragment

Return Value

AbstractPaginator|string|null

at line 206
AbstractPaginator appends(array|string|null $key, array|string|null $value = null)

Add a set of query string values to the paginator.

Parameters

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

Return Value

AbstractPaginator

at line 225
protected AbstractPaginator appendArray(array $keys)

Add an array of query string values.

Parameters

array $keys

Return Value

AbstractPaginator

at line 239
AbstractPaginator withQueryString()

Add all current query string values to the paginator.

Return Value

AbstractPaginator

at line 253
protected AbstractPaginator addQuery(string $key, mixed $value)

Add a query string value to the paginator.

Parameters

string $key
mixed $value

Return Value

AbstractPaginator

at line 265
protected string buildFragment()

Build the full fragment portion of a URL.

Return Value

string

at line 276
AbstractPaginator loadMorph(string $relation, array $relations)

Load a set of relationships onto the mixed relationship collection.

Parameters

string $relation
array $relations

Return Value

AbstractPaginator

at line 290
AbstractPaginator loadMorphCount(string $relation, array $relations)

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

Parameters

string $relation
array $relations

Return Value

AbstractPaginator

at line 303
array items()

Get the slice of items being paginated.

Return Value

array

at line 311
int|null firstItem()

Get the number of the first item in the slice.

Return Value

int|null

at line 319
int|null lastItem()

Get the number of the last item in the slice.

Return Value

int|null

at line 334
AbstractPaginator through(callable $callback)

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

Parameters

callable $callback

Return Value

AbstractPaginator

at line 344
int perPage()

Get the number of items shown per page.

Return Value

int

at line 352
bool hasPages()

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

Return Value

bool

at line 360
bool onFirstPage()

Determine if the paginator is on the first page.

Return Value

bool

at line 368
bool onLastPage()

Determine if the paginator is on the last page.

Return Value

bool

at line 376
int currentPage()

Get the current page.

Return Value

int

at line 384
string getPageName()

Get the query string variable used to store the page.

Return Value

string

at line 394
AbstractPaginator setPageName(string $name)

Set the query string variable used to store the page.

Parameters

string $name

Return Value

AbstractPaginator

at line 406
AbstractPaginator withPath(string $path)

Set the base path to assign to all URLs.

Parameters

string $path

Return Value

AbstractPaginator

at line 416
AbstractPaginator setPath(string $path)

Set the base path to assign to all URLs.

Parameters

string $path

Return Value

AbstractPaginator

at line 428
AbstractPaginator onEachSide(int $count)

Set the number of links to display on each side of current page link.

Parameters

int $count

Return Value

AbstractPaginator

at line 438
string|null path()

Get the base path for paginator generated URLs.

Return Value

string|null

at line 446
static string resolveCurrentPath(string $default = '/')

Resolve the current request path or return the default value.

Parameters

string $default

Return Value

string

at line 461
static void currentPathResolver(Closure $resolver)

Set the current request path resolver callback.

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

Parameters

Closure $resolver

Return Value

void

at line 469
static int resolveCurrentPage(string $pageName = 'page', int $default = 1)

Resolve the current page or return the default value.

Parameters

string $pageName
int $default

Return Value

int

at line 484
static void currentPageResolver(Closure $resolver)

Set the current page resolver callback.

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

Parameters

Closure $resolver

Return Value

void

at line 492
static string|array|null resolveQueryString(string|array|null $default = null)

Resolve the query string or return the default value.

Parameters

string|array|null $default

Return Value

string|array|null

at line 507
static void queryStringResolver(Closure $resolver)

Set with query string resolver callback.

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

Parameters

Closure $resolver

Return Value

void

at line 515
static mixed viewFactory()

Get an instance of the view factory from the resolver.

Return Value

mixed

at line 526
static void viewFactoryResolver(Closure $resolver)

Set the view factory resolver callback.

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

Parameters

Closure $resolver

Return Value

void

at line 537
static void defaultView(string $view)

Set the default pagination view.

Boot-only. The view name persists in a static property for the worker lifetime and applies to every subsequent paginator render.

Parameters

string $view

Return Value

void

at line 548
static void defaultSimpleView(string $view)

Set the default "simple" pagination view.

Boot-only. The view name persists in a static property for the worker lifetime and applies to every subsequent simple-paginator render.

Parameters

string $view

Return Value

void

at line 559
static void useTailwind()

Indicate that Tailwind styling should be used for generated links.

Boot-only. Sets the default view names in static properties for the worker lifetime; applies to every subsequent paginator render.

Return Value

void

at line 568
static void flushState()

Flush all static state.

Return Value

void

at line 583
Traversable getIterator()

Get an iterator for the items.

Return Value

Traversable

at line 591
bool isEmpty()

Determine if the list of items is empty.

Return Value

bool

at line 599
bool isNotEmpty()

Determine if the list of items is not empty.

Return Value

bool

at line 607
int count()

Get the number of items for the current page.

Return Value

int

at line 617
Collection getCollection()

Get the paginator's underlying collection.

Return Value

Collection

at line 628
AbstractPaginator setCollection(Collection $collection)

Set the paginator's underlying collection.

Parameters

Collection $collection

Return Value

AbstractPaginator

at line 640
array getOptions()

Get the paginator options.

Return Value

array

at line 650
bool offsetExists(TKey $key)

Determine if the given item exists.

Parameters

TKey $key

Return Value

bool

at line 661
mixed offsetGet(TKey $key)

Get the item at the given offset.

Parameters

TKey $key

Return Value

mixed

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

Set the item at the given offset.

Parameters

null|TKey $key
TValue $value

Return Value

void

at line 682
void offsetUnset(TKey $key)

Unset the item at the given key.

Parameters

TKey $key

Return Value

void

at line 690
string toHtml()

Render the contents of the paginator to HTML.

Return Value

string

at line 702
mixed __call(string $method, array $parameters)

Make dynamic calls into the collection.

Parameters

string $method
array $parameters

Return Value

mixed

at line 710
string __toString()

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

Return Value

string

at line 727
CanBeEscapedWhenCastToString escapeWhenCastingToString(bool $escape = true)

Indicate that the paginator's string representation should be escaped when __toString is invoked.

Parameters

bool $escape

Return Value

CanBeEscapedWhenCastToString