Paginator

class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable, Paginator (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 $hasMore Determine if there are more items in the data source.

Methods

bool isValidPageNumber(int $page)

Determine if the given value is a valid page number.

from AbstractPaginator
string|null previousPageUrl()

Get the URL for the previous page.

from AbstractPaginator
array getUrlRange(int $start, int $end)

Create a range of pagination URLs.

from AbstractPaginator
string url(int $page)

Get the URL for a given page number.

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

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

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

Add a set of query string values to the paginator.

from AbstractPaginator
$this appendArray(array $keys)

Add an array of query string values.

from AbstractPaginator
$this addQuery(string $key, string $value)

Add a query string value to the paginator.

from AbstractPaginator
string buildFragment()

Build the full fragment portion of a URL.

from AbstractPaginator
array items()

Get the slice of items being paginated.

from AbstractPaginator
int firstItem()

Get the number of the first item in the slice.

from AbstractPaginator
int lastItem()

Get the number of the last item in the slice.

from AbstractPaginator
int perPage()

Get the number of items shown per page.

from AbstractPaginator
bool hasPages()

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

from AbstractPaginator
bool onFirstPage()

Determine if the paginator is on the first page.

from AbstractPaginator
int currentPage()

Get the current page.

from AbstractPaginator
string getPageName()

Get the query string variable used to store the page.

from AbstractPaginator
$this setPageName(string $name)

Set the query string variable used to store the page.

from AbstractPaginator
$this withPath(string $path)

Set the base path to assign to all URLs.

from AbstractPaginator
$this setPath(string $path)

Set the base path to assign to all URLs.

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

Resolve the current request path or return the default value.

from AbstractPaginator
static void currentPathResolver(Closure $resolver)

Set the current request path resolver callback.

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

Resolve the current page or return the default value.

from AbstractPaginator
static void currentPageResolver(Closure $resolver)

Set the current page resolver callback.

from AbstractPaginator
static Factory viewFactory()

Get an instance of the view factory from the resolver.

from AbstractPaginator
static void viewFactoryResolver(Closure $resolver)

Set the view factory resolver callback.

from AbstractPaginator
static void defaultView(string $view)

Set the default pagination view.

from AbstractPaginator
static void defaultSimpleView(string $view)

Set the default "simple" pagination view.

from AbstractPaginator
ArrayIterator getIterator()

Get an iterator for the items.

from AbstractPaginator
bool isEmpty()

Determine if the list of items is empty or not.

from AbstractPaginator
bool isNotEmpty()

Determine if the list of items is not empty.

from AbstractPaginator
int count()

Get the number of items for the current page.

from AbstractPaginator
Collection getCollection()

Get the paginator's underlying collection.

from AbstractPaginator
$this setCollection(Collection $collection)

Set the paginator's underlying collection.

from AbstractPaginator
bool offsetExists(mixed $key)

Determine if the given item exists.

from AbstractPaginator
mixed offsetGet(mixed $key)

Get the item at the given offset.

from AbstractPaginator
void offsetSet(mixed $key, mixed $value)

Set the item at the given offset.

from AbstractPaginator
void offsetUnset(mixed $key)

Unset the item at the given key.

from AbstractPaginator
string toHtml()

Render the contents of the paginator to HTML.

from AbstractPaginator
mixed __call(string $method, array $parameters)

Make dynamic calls into the collection.

from AbstractPaginator
string __toString()

Render the contents of the paginator when casting to string.

from AbstractPaginator
void __construct(mixed $items, int $perPage, int|null $currentPage = null, array $options = [])

Create a new paginator instance.

int setCurrentPage(int $currentPage)

Get the current page for the request.

void setItems(mixed $items)

Set the items for the paginator.

string|null nextPageUrl()

Get the URL for the next page.

string 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 the given view.

$this hasMorePagesWhen(bool $hasMore = true)

Manually indicate that the paginator does have more pages.

bool hasMorePages()

Determine if there are more items in the data source.

array toArray()

Get the instance as an array.

array jsonSerialize()

Convert the object into something JSON serializable.

string toJson(int $options)

Convert the object to its JSON representation.

Details

protected bool isValidPageNumber(int $page)

Determine if the given value is a valid page number.

Parameters

int $page

Return Value

bool

string|null previousPageUrl()

Get the URL for the previous page.

Return Value

string|null

array getUrlRange(int $start, int $end)

Create a range of pagination URLs.

Parameters

int $start
int $end

Return Value

array

string url(int $page)

Get the URL for a given page number.

Parameters

int $page

Return Value

string

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

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

Parameters

string|null $fragment

Return Value

$this|string|null

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

Add a set of query string values to the paginator.

Parameters

array|string $key
string|null $value

Return Value

$this

protected $this appendArray(array $keys)

Add an array of query string values.

Parameters

array $keys

Return Value

$this

protected $this addQuery(string $key, string $value)

Add a query string value to the paginator.

Parameters

string $key
string $value

Return Value

$this

protected string buildFragment()

Build the full fragment portion of a URL.

Return Value

string

array items()

Get the slice of items being paginated.

Return Value

array

int firstItem()

Get the number of the first item in the slice.

Return Value

int

int lastItem()

Get the number of the last item in the slice.

Return Value

int

int perPage()

Get the number of items shown per page.

Return Value

int

bool hasPages()

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

Return Value

bool

bool onFirstPage()

Determine if the paginator is on the first page.

Return Value

bool

int currentPage()

Get the current page.

Return Value

int

string getPageName()

Get the query string variable used to store the page.

Return Value

string

$this setPageName(string $name)

Set the query string variable used to store the page.

Parameters

string $name

Return Value

$this

$this withPath(string $path)

Set the base path to assign to all URLs.

Parameters

string $path

Return Value

$this

$this setPath(string $path)

Set the base path to assign to all URLs.

Parameters

string $path

Return Value

$this

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

Resolve the current request path or return the default value.

Parameters

string $default

Return Value

string

static void currentPathResolver(Closure $resolver)

Set the current request path resolver callback.

Parameters

Closure $resolver

Return Value

void

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

static void currentPageResolver(Closure $resolver)

Set the current page resolver callback.

Parameters

Closure $resolver

Return Value

void

static Factory viewFactory()

Get an instance of the view factory from the resolver.

Return Value

Factory

static void viewFactoryResolver(Closure $resolver)

Set the view factory resolver callback.

Parameters

Closure $resolver

Return Value

void

static void defaultView(string $view)

Set the default pagination view.

Parameters

string $view

Return Value

void

static void defaultSimpleView(string $view)

Set the default "simple" pagination view.

Parameters

string $view

Return Value

void

ArrayIterator getIterator()

Get an iterator for the items.

Return Value

ArrayIterator

bool isEmpty()

Determine if the list of items is empty or not.

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

$this setCollection(Collection $collection)

Set the paginator's underlying collection.

Parameters

Collection $collection

Return Value

$this

bool offsetExists(mixed $key)

Determine if the given item exists.

Parameters

mixed $key

Return Value

bool

mixed offsetGet(mixed $key)

Get the item at the given offset.

Parameters

mixed $key

Return Value

mixed

void offsetSet(mixed $key, mixed $value)

Set the item at the given offset.

Parameters

mixed $key
mixed $value

Return Value

void

void offsetUnset(mixed $key)

Unset the item at the given key.

Parameters

mixed $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 string.

Return Value

string

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

Create a new paginator instance.

Parameters

mixed $items
int $perPage
int|null $currentPage
array $options (path, query, fragment, pageName)

Return Value

void

protected int setCurrentPage(int $currentPage)

Get the current page for the request.

Parameters

int $currentPage

Return Value

int

protected void setItems(mixed $items)

Set the items for the paginator.

Parameters

mixed $items

Return Value

void

string|null nextPageUrl()

Get the URL for the next page.

Return Value

string|null

Render the paginator using the given view.

Parameters

string|null $view
array $data

Return Value

string

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

Render the paginator using the given view.

Parameters

string|null $view
array $data

Return Value

string

$this hasMorePagesWhen(bool $hasMore = true)

Manually indicate that the paginator does have more pages.

Parameters

bool $hasMore

Return Value

$this

bool hasMorePages()

Determine if there are more items in the data source.

Return Value

bool

array toArray()

Get the instance as an array.

Return Value

array

array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

string toJson(int $options)

Convert the object to its JSON representation.

Parameters

int $options

Return Value

string

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.6/Illuminate/Pagination/Paginator.html