When creating a new instance of Laravel's Paginator, I know how to use all parameters of it's __construct
method, except one. According to the Paginator Laravel API page, it should look like this:
void __construct(mixed $items, int $perPage, int|null $currentPage = null, array $options = [])
I need help with the options
parameter. The page says:
Parameters ... array $options (path, query, fragment, pageName)
What do all these options do and how do I use them? I couldn't find any proper documentation for this, and all information I have is a few examples of other fellow coders on SO using the path
element.
Surely not needed anymore, but for future visits:
Nitpicking the docs to find each possible value the following was found:
Given the 4 possible values of the array (feel free to omit any one of the 'key' => value
pairs):
['path' => '/categories/misc', # Base Path for all generated links.
'query' => ['sort' => 'age', # Some additional variables on the links.
'thing' => 5],
'fragment' => 'SeaTurtles', # Value that will appear after the '#' sign.
'pageName' => 'myPageNumber'] /* The name of the variable used for
pagination that will appear on the
url/request. The default value is 'page'. */
Taking some "page number 3" as example case, these options would generate links in the form:
http[s]://theSite.com/categories/misc?myPageNumber=3&sort=age&thing=5#SeaTurtles
'path' -> Documentation for Path Option
'query' -> Documentation for Query Option (Note I could be mistaken on the syntax of this one.)
'fragment' -> Documentation for Fragment Option
'pageName' -> No Documentation. In AbstractPaginator Class it shows to be the default page number variable name that appears in the url after the '?'. It is shown in the 'path' Documentation.