LengthAwarePaginator
class LengthAwarePaginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, Jsonable, JsonSerializable, LengthAwarePaginator
Traits
Constants
| protected DEFAULT_VIEW |
The default pagination view name. |
| protected DEFAULT_SIMPLE_VIEW |
The default simple pagination view name. |
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<array-key, 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 int | $total | The total number of items before slicing. |
|
| protected int | $lastPage | The last available page. |
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.
Render the paginator using the given view.
Get the paginator links as a collection (for JSON responses).
Get the array of elements to pass to the view.
Get the total number of items being paginated.
Get the URL for the next page.
Get the last page.
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 17
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
in
TransformsToResourceCollection at line 24
ResourceCollection
toResourceCollection(string|null $resourceClass = null)
Create a new resource collection instance for the given resource.
in
TransformsToResourceCollection at line 38
protected ResourceCollection
guessResourceCollection()
Guess the resource collection for the items.
in
TransformsToResourceCollection at line 93
protected string|null
resolveResourceFromAttribute(string $class)
Get the resource class from the class attribute.
in
TransformsToResourceCollection at line 112
protected string|null
resolveResourceCollectionFromAttribute(string $class)
Get the resource collection class from the class attribute.
at line 91
Htmlable
render(string|null $view = null, array $data = [])
Render the paginator using the given view.
at line 164
bool
hasMorePages()
Determine if there are more items in the data source.
in
AbstractPaginator at line 148
protected bool
isValidPageNumber(int $page)
Determine if the given value is a valid page number.
in
AbstractPaginator at line 156
string|null
previousPageUrl()
Get the URL for the previous page.
in
AbstractPaginator at line 170
array
getUrlRange(int $start, int $end)
Create a range of pagination URLs.
in
AbstractPaginator at line 180
string
url(int $page)
Get the URL for a given page number.
in
AbstractPaginator at line 206
AbstractPaginator|string|null
fragment(string|null $fragment = null)
Get / set the URL fragment to be appended to URLs.
in
AbstractPaginator at line 222
AbstractPaginator
appends(array|int|string|null $key, array|bool|float|int|string|null $value = null)
Add a set of query string values to the paginator.
in
AbstractPaginator at line 243
protected AbstractPaginator
appendArray(array $keys)
Add an array of query string values.
in
AbstractPaginator at line 257
AbstractPaginator
withQueryString()
Add all current query string values to the paginator.
in
AbstractPaginator at line 271
protected AbstractPaginator
addQuery(int|string $key, mixed $value)
Add a query string value to the paginator.
in
AbstractPaginator at line 283
protected string
buildFragment()
Build the full fragment portion of a URL.
in
AbstractPaginator at line 297
AbstractPaginator
loadMorph(string $relation, array $relations)
Load a set of relationships onto the mixed relationship collection.
in
AbstractPaginator at line 314
AbstractPaginator
loadMorphCount(string $relation, array $relations)
Load a set of relationship counts onto the mixed relationship collection.
in
AbstractPaginator at line 327
array
items()
Get the slice of items being paginated.
in
AbstractPaginator at line 335
int|null
firstItem()
Get the number of the first item in the slice.
in
AbstractPaginator at line 343
int|null
lastItem()
Get the number of the last item in the slice.
in
AbstractPaginator at line 358
AbstractPaginator
through(callable $callback)
Transform each item in the slice of items using a callback.
in
AbstractPaginator at line 368
int
perPage()
Get the number of items shown per page.
in
AbstractPaginator at line 376
bool
hasPages()
Determine if there are enough items to split into multiple pages.
in
AbstractPaginator at line 384
bool
onFirstPage()
Determine if the paginator is on the first page.
in
AbstractPaginator at line 392
bool
onLastPage()
Determine if the paginator is on the last page.
in
AbstractPaginator at line 400
int
currentPage()
Get the current page.
in
AbstractPaginator at line 408
string
getPageName()
Get the query string variable used to store the page.
in
AbstractPaginator at line 418
AbstractPaginator
setPageName(string $name)
Set the query string variable used to store the page.
in
AbstractPaginator at line 430
AbstractPaginator
withPath(string $path)
Set the base path to assign to all URLs.
in
AbstractPaginator at line 440
AbstractPaginator
setPath(string $path)
Set the base path to assign to all URLs.
in
AbstractPaginator at line 452
AbstractPaginator
onEachSide(int $count)
Set the number of links to display on each side of current page link.
in
AbstractPaginator at line 462
string|null
path()
Get the base path for paginator generated URLs.
in
AbstractPaginator at line 470
static string
resolveCurrentPath(string $default = '/')
Resolve the current request path or return the default value.
in
AbstractPaginator at line 485
static void
currentPathResolver(Closure $resolver)
Set the current request path resolver callback.
The resolver persists in a static property for the worker lifetime and runs on every subsequent paginator's path lookup.
in
AbstractPaginator at line 494
static int
resolveCurrentPage(string $pageName = 'page', int $default = 1)
Resolve the current page or return the default value.
in
AbstractPaginator at line 509
static void
currentPageResolver(Closure $resolver)
Set the current page resolver callback.
The resolver persists in a static property for the worker lifetime and runs on every subsequent paginator's page lookup.
in
AbstractPaginator at line 518
static string|array|null
resolveQueryString(string|array|null $default = null)
Resolve the query string or return the default value.
in
AbstractPaginator at line 533
static void
queryStringResolver(Closure $resolver)
Set with query string resolver callback.
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 542
static Factory
viewFactory()
Get an instance of the view factory from the resolver.
in
AbstractPaginator at line 553
static void
viewFactoryResolver(Closure $resolver)
Set the view factory resolver callback.
The resolver persists in a static property for the worker lifetime and runs on every subsequent paginator render.
in
AbstractPaginator at line 565
static void
defaultView(string $view)
Set the default pagination view.
The view name persists in a static property for the worker lifetime and applies to every subsequent paginator render.
in
AbstractPaginator at line 577
static void
defaultSimpleView(string $view)
Set the default "simple" pagination view.
The view name persists in a static property for the worker lifetime and applies to every subsequent simple-paginator render.
in
AbstractPaginator at line 589
static void
useTailwind()
Indicate that Tailwind styling should be used for generated links.
Sets the default view names in static properties for the worker lifetime; applies to every subsequent paginator render.
in
AbstractPaginator at line 601
static void
flushState()
Flush all static state.
in
AbstractPaginator at line 616
Traversable
getIterator()
Get an iterator for the items.
in
AbstractPaginator at line 624
bool
isEmpty()
Determine if the list of items is empty.
in
AbstractPaginator at line 632
bool
isNotEmpty()
Determine if the list of items is not empty.
in
AbstractPaginator at line 640
int
count()
Get the number of items for the current page.
in
AbstractPaginator at line 650
Collection
getCollection()
Get the paginator's underlying collection.
in
AbstractPaginator at line 667
AbstractPaginator
setCollection(Collection $collection)
Set the paginator's underlying collection.
in
AbstractPaginator at line 679
array
getOptions()
Get the paginator options.
in
AbstractPaginator at line 689
bool
offsetExists(TKey $offset)
Determine if the given item exists.
in
AbstractPaginator at line 700
mixed
offsetGet(TKey $offset)
Get the item at the given offset.
in
AbstractPaginator at line 711
void
offsetSet(null|TKey $offset, TValue $value)
Set the item at the given offset.
in
AbstractPaginator at line 721
void
offsetUnset(TKey $offset)
Unset the item at the given key.
in
AbstractPaginator at line 729
string
toHtml()
Render the contents of the paginator to HTML.
in
AbstractPaginator at line 741
mixed
__call(string $method, array $parameters)
Make dynamic calls into the collection.
in
AbstractPaginator at line 749
string
__toString()
Render the contents of the paginator when casting to a string.
in
AbstractPaginator at line 766
CanBeEscapedWhenCastToString
escapeWhenCastingToString(bool $escape = true)
Indicate that the paginator's string representation should be escaped when __toString is invoked.
at line 50
__construct(mixed $items, int $total, int $perPage, int|null $currentPage = null, array $options = [])
Create a new paginator instance.
at line 69
protected int
setCurrentPage(int|null $currentPage, string $pageName)
Get the current page for the request.
at line 81
Htmlable
links(string|null $view = null, array $data = [])
Render the paginator using the given view.
at line 106
Collection
linkCollection()
Get the paginator links as a collection (for JSON responses).
at line 140
protected array
elements()
Get the array of elements to pass to the view.
at line 156
int
total()
Get the total number of items being paginated.
at line 172
string|null
nextPageUrl()
Get the URL for the next page.
at line 184
int
lastPage()
Get the last page.
at line 194
array
toArray()
Get the instance as an array.
at line 219
array
jsonSerialize()
Convert the object into something JSON serializable.
at line 229
string
toJson(int $options = 0)
Convert the object to its JSON representation.
at line 239
string
toPrettyJson(int $options = 0)
Convert the object to pretty print formatted JSON.