LengthAwarePaginator
class LengthAwarePaginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable, LengthAwarePaginator (View source)
Properties
protected Collection | $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 | $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 |
static protected Closure | $currentPathResolver | The current path resolver callback. |
from AbstractPaginator |
static protected Closure | $currentPageResolver | The current page resolver callback. |
from AbstractPaginator |
static protected Closure | $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
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 a query string value to the paginator.
Determine if there are enough items to split into multiple pages.
Set the query string variable used to store the page.
Resolve the current request path or return the default value.
Resolve the current page or return the default value.
Get an instance of the view factory from the resolver.
Set the default "simple" pagination view.
Make dynamic calls into the collection.
Render the contents of the paginator when casting to string.
Create a new paginator instance.
Get the current page for the request.
Render the paginator using the given view.
Render the paginator using a given view.
Get the array of elements to pass to the view.
Determine the total number of items in the data store.
Determine if there is more items in the data store.
The URL for the next page, or null.
Get the page number of the last available page.
Get the instance as an array.
Convert the object into something JSON serializable.
Convert the object to its JSON representation.
Details
protected 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.
$this|string|null
fragment(string|null $fragment = null)
Get / set the URL fragment to be appended to URLs.
$this
appends(array|string $key, string|null $value = null)
Add a set of query string values to the paginator.
protected $this
appendArray(array $keys)
Add an array of query string values.
protected $this
addQuery(string $key, string $value)
Add a query string value to the paginator.
protected string
buildFragment()
Build the full fragment portion of a URL.
array
items()
Get the slice of items being paginated.
int
firstItem()
Get the number of the first item in the slice.
int
lastItem()
Get the number of the last item in the slice.
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.
int
currentPage()
Get the current page.
string
getPageName()
Get the query string variable used to store the page.
$this
setPageName(string $name)
Set the query string variable used to store the page.
$this
withPath(string $path)
Set the base path to assign to all URLs.
$this
setPath(string $path)
Set the base path to assign to all 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 Factory
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.
ArrayIterator
getIterator()
Get an iterator for the items.
bool
isEmpty()
Determine if the list of items is empty or not.
bool
isNotEmpty()
Determine if the list of items is not empty.
int
count()
Get the number of items for the current page.
Collection
getCollection()
Get the paginator's underlying collection.
$this
setCollection(Collection $collection)
Set the paginator's underlying collection.
bool
offsetExists(mixed $key)
Determine if the given item exists.
mixed
offsetGet(mixed $key)
Get the item at the given offset.
void
offsetSet(mixed $key, mixed $value)
Set the item at the given offset.
void
offsetUnset(mixed $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 string.
void
__construct(mixed $items, int $total, int $perPage, int|null $currentPage = null, array $options = [])
Create a new paginator instance.
protected int
setCurrentPage(int $currentPage, string $pageName)
Get the current page for the request.
HtmlString
links(string|null $view = null, array $data = [])
Render the paginator using the given view.
string
render(string|null $view = null, array $data = [])
Render the paginator using a given view.
protected array
elements()
Get the array of elements to pass to the view.
int
total()
Determine the total number of items in the data store.
bool
hasMorePages()
Determine if there is more items in the data store.
string|null
nextPageUrl()
The URL for the next page, or null.
int
lastPage()
Get the page number of the last available 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.