Paginator
class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, Jsonable, JsonSerializable, Paginator
Traits
Properties
| protected TValue> | $items | All of the items being paginated. |
from AbstractPaginator |
| protected int | $perPage | The number of items to be shown per page. |
from AbstractPaginator |
| protected int | $currentPage | The current page being "viewed". |
from AbstractPaginator |
| protected string | $path | The base path to assign to all URLs. |
from AbstractPaginator |
| protected array<string, mixed> | $query | The query parameters to add to all URLs. |
from AbstractPaginator |
| protected string|null | $fragment | The URL fragment to add to all URLs. |
from AbstractPaginator |
| protected string | $pageName | The query string variable used to store the page. |
from AbstractPaginator |
| protected bool | $escapeWhenCastingToString | Indicates that the paginator's string representation should be escaped when __toString is invoked. |
from AbstractPaginator |
| int | $onEachSide | The number of links to display on each side of current page link. |
from AbstractPaginator |
| protected array<string, mixed> | $options | The paginator options. |
from AbstractPaginator |
| static protected Closure|null | $currentPathResolver | The current path resolver callback. |
from AbstractPaginator |
| static protected Closure|null | $currentPageResolver | The current page resolver callback. |
from AbstractPaginator |
| static protected Closure|null | $queryStringResolver | The query string resolver callback. |
from AbstractPaginator |
| static protected Closure|null | $viewFactoryResolver | The view factory resolver callback. |
from AbstractPaginator |
| static string | $defaultView | The default pagination view. |
from AbstractPaginator |
| static string | $defaultSimpleView | The default "simple" pagination view. |
from AbstractPaginator |
| protected bool | $hasMore | Determine if there are more items in the data source. |
Methods
Forward a method call to the given object.
Forward a method call to the given object, returning $this if the forwarded call returned itself.
Throw a bad method call exception for the given method.
Call the given Closure with this instance then return the instance.
Create a new resource collection instance for the given resource.
Guess the resource collection for the items.
Get the resource class from the class attribute.
Get the resource collection class from the class attribute.
Render the paginator using the given view.
Determine if there are more items in the data source.
Determine if the given value is a valid page number.
Get / set the URL fragment to be appended to URLs.
Add a set of query string values to the paginator.
Add an array of query string values.
Add all current query string values to the paginator.
Add a query string value to the paginator.
Load a set of relationships onto the mixed relationship collection.
Load a set of relationship counts onto the mixed relationship collection.
Transform each item in the slice of items using a callback.
Determine if there are enough items to split into multiple pages.
Set the query string variable used to store the page.
Set the base path to assign to all URLs.
Set the base path to assign to all URLs.
Set the number of links to display on each side of current page link.
Resolve the current request path or return the default value.
Resolve the current page or return the default value.
Resolve the query string or return the default value.
Get an instance of the view factory from the resolver.
Set the default "simple" pagination view.
Indicate that Tailwind styling should be used for generated links.
Set the item at the given offset.
Make dynamic calls into the collection.
Render the contents of the paginator when casting to a string.
Indicate that the paginator's string representation should be escaped when __toString is invoked.
Create a new paginator instance.
Get the current page for the request.
Set the items for the paginator.
Get the URL for the next page.
Render the paginator using the given view.
Manually indicate that the paginator does have more pages.
Get the instance as an array.
Convert the object into something JSON serializable.
Convert the object to its JSON representation.
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.
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.
in
ForwardsCalls at line 66
static protected never
throwBadMethodCallException(string $method)
Throw a bad method call exception for the given method.
in
Tappable at line 15
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
in
TransformsToResourceCollection at line 25
ResourceCollection
toResourceCollection(string|null $resourceClass = null)
Create a new resource collection instance for the given resource.
in
TransformsToResourceCollection at line 39
protected ResourceCollection
guessResourceCollection()
Guess the resource collection for the items.
in
TransformsToResourceCollection at line 92
protected string|null
resolveResourceFromAttribute(string $class)
Get the resource class from the class attribute.
in
TransformsToResourceCollection at line 111
protected string|null
resolveResourceCollectionFromAttribute(string $class)
Get the resource collection class from the class attribute.
at line 108
Htmlable
render(string|null $view = null, array $data = [])
Render the paginator using the given view.
at line 130
bool
hasMorePages()
Determine if there are more items in the data source.
in
AbstractPaginator at line 132
protected bool
isValidPageNumber(int $page)
Determine if the given value is a valid page number.
in
AbstractPaginator at line 140
string|null
previousPageUrl()
Get the URL for the previous page.
in
AbstractPaginator at line 154
array
getUrlRange(int $start, int $end)
Create a range of pagination URLs.
in
AbstractPaginator at line 164
string
url(int $page)
Get the URL for a given page number.
in
AbstractPaginator at line 190
AbstractPaginator|string|null
fragment(string|null $fragment = null)
Get / set the URL fragment to be appended to URLs.
in
AbstractPaginator at line 206
AbstractPaginator
appends(array|string|null $key, array|string|null $value = null)
Add a set of query string values to the paginator.
in
AbstractPaginator at line 225
protected AbstractPaginator
appendArray(array $keys)
Add an array of query string values.
in
AbstractPaginator at line 239
AbstractPaginator
withQueryString()
Add all current query string values to the paginator.
in
AbstractPaginator at line 253
protected AbstractPaginator
addQuery(string $key, mixed $value)
Add a query string value to the paginator.
in
AbstractPaginator at line 265
protected string
buildFragment()
Build the full fragment portion of a URL.
in
AbstractPaginator at line 276
AbstractPaginator
loadMorph(string $relation, array $relations)
Load a set of relationships onto the mixed relationship collection.
in
AbstractPaginator at line 290
AbstractPaginator
loadMorphCount(string $relation, array $relations)
Load a set of relationship counts onto the mixed relationship collection.
in
AbstractPaginator at line 303
array
items()
Get the slice of items being paginated.
in
AbstractPaginator at line 311
int|null
firstItem()
Get the number of the first item in the slice.
in
AbstractPaginator at line 319
int|null
lastItem()
Get the number of the last item in the slice.
in
AbstractPaginator at line 334
AbstractPaginator
through(callable $callback)
Transform each item in the slice of items using a callback.
in
AbstractPaginator at line 344
int
perPage()
Get the number of items shown per page.
in
AbstractPaginator at line 352
bool
hasPages()
Determine if there are enough items to split into multiple pages.
in
AbstractPaginator at line 360
bool
onFirstPage()
Determine if the paginator is on the first page.
in
AbstractPaginator at line 368
bool
onLastPage()
Determine if the paginator is on the last page.
in
AbstractPaginator at line 376
int
currentPage()
Get the current page.
in
AbstractPaginator at line 384
string
getPageName()
Get the query string variable used to store the page.
in
AbstractPaginator at line 394
AbstractPaginator
setPageName(string $name)
Set the query string variable used to store the page.
in
AbstractPaginator at line 406
AbstractPaginator
withPath(string $path)
Set the base path to assign to all URLs.
in
AbstractPaginator at line 416
AbstractPaginator
setPath(string $path)
Set the base path to assign to all URLs.
in
AbstractPaginator at line 428
AbstractPaginator
onEachSide(int $count)
Set the number of links to display on each side of current page link.
in
AbstractPaginator at line 438
string|null
path()
Get the base path for paginator generated URLs.
in
AbstractPaginator at line 446
static string
resolveCurrentPath(string $default = '/')
Resolve the current request path or return the default value.
in
AbstractPaginator 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.
in
AbstractPaginator at line 469
static int
resolveCurrentPage(string $pageName = 'page', int $default = 1)
Resolve the current page or return the default value.
in
AbstractPaginator 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.
in
AbstractPaginator at line 492
static string|array|null
resolveQueryString(string|array|null $default = null)
Resolve the query string or return the default value.
in
AbstractPaginator 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.
in
AbstractPaginator at line 515
static mixed
viewFactory()
Get an instance of the view factory from the resolver.
in
AbstractPaginator 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.
in
AbstractPaginator 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.
in
AbstractPaginator 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.
in
AbstractPaginator 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.
in
AbstractPaginator at line 568
static void
flushState()
Flush all static state.
in
AbstractPaginator at line 583
Traversable
getIterator()
Get an iterator for the items.
in
AbstractPaginator at line 591
bool
isEmpty()
Determine if the list of items is empty.
in
AbstractPaginator at line 599
bool
isNotEmpty()
Determine if the list of items is not empty.
in
AbstractPaginator at line 607
int
count()
Get the number of items for the current page.
in
AbstractPaginator at line 617
Collection
getCollection()
Get the paginator's underlying collection.
in
AbstractPaginator at line 628
AbstractPaginator
setCollection(Collection $collection)
Set the paginator's underlying collection.
in
AbstractPaginator at line 640
array
getOptions()
Get the paginator options.
in
AbstractPaginator at line 650
bool
offsetExists(TKey $key)
Determine if the given item exists.
in
AbstractPaginator at line 661
mixed
offsetGet(TKey $key)
Get the item at the given offset.
in
AbstractPaginator at line 672
void
offsetSet(null|TKey $key, TValue $value)
Set the item at the given offset.
in
AbstractPaginator at line 682
void
offsetUnset(TKey $key)
Unset the item at the given key.
in
AbstractPaginator at line 690
string
toHtml()
Render the contents of the paginator to HTML.
in
AbstractPaginator at line 702
mixed
__call(string $method, array $parameters)
Make dynamic calls into the collection.
in
AbstractPaginator at line 710
string
__toString()
Render the contents of the paginator when casting to a string.
in
AbstractPaginator at line 727
CanBeEscapedWhenCastToString
escapeWhenCastingToString(bool $escape = true)
Indicate that the paginator's string representation should be escaped when __toString is invoked.
at line 42
__construct(mixed $items, int $perPage, int|null $currentPage = null, array $options = [])
Create a new paginator instance.
at line 60
protected int
setCurrentPage(int|null $currentPage)
Get the current page for the request.
at line 72
protected void
setItems(mixed $items)
Set the items for the paginator.
at line 84
string|null
nextPageUrl()
Get the URL for the next page.
at line 98
Htmlable
links(string|null $view = null, array $data = [])
Render the paginator using the given view.
at line 120
Paginator
hasMorePagesWhen(bool $hasMore = true)
Manually indicate that the paginator does have more pages.
at line 140
array
toArray()
Get the instance as an array.
at line 161
array
jsonSerialize()
Convert the object into something JSON serializable.
at line 169
string
toJson(int $options = 0)
Convert the object to its JSON representation.
at line 177
string
toPrettyJson(int $options = 0)
Convert the object to pretty print formatted JSON.