Skip to content

Commit 59c0cec

Browse files
authored
Add 'page' field to paginator links (#56603)
* Add 'page' field to paginator links * Update test to check 'page' field in pagination links
1 parent 30fb902 commit 59c0cec

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Illuminate/Pagination/LengthAwarePaginator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,19 @@ public function linkCollection()
121121
return [
122122
'url' => $url,
123123
'label' => (string) $page,
124+
'page' => $page,
124125
'active' => $this->currentPage() === $page,
125126
];
126127
});
127128
})->prepend([
128129
'url' => $this->previousPageUrl(),
129130
'label' => function_exists('__') ? __('pagination.previous') : 'Previous',
131+
'page' => $this->currentPage() > 1 ? $this->currentPage() - 1 : null,
130132
'active' => false,
131133
])->push([
132134
'url' => $this->nextPageUrl(),
133135
'label' => function_exists('__') ? __('pagination.next') : 'Next',
136+
'page' => $this->hasMorePages() ? $this->currentPage() + 1 : null,
134137
'active' => false,
135138
]);
136139
}

tests/Integration/Http/ResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ public function testResourcesMayCustomizeJsonOptionsOnPaginatedResponse()
901901
);
902902

903903
$this->assertEquals(
904-
'{"data":[{"id":5,"title":"Test Title","reading_time":3.0}],"links":{"first":"\/?page=1","last":"\/?page=1","prev":null,"next":null},"meta":{"current_page":1,"from":1,"last_page":1,"links":[{"url":null,"label":"« Previous","active":false},{"url":"\/?page=1","label":"1","active":true},{"url":null,"label":"Next »","active":false}],"path":"\/","per_page":15,"to":1,"total":10}}',
904+
'{"data":[{"id":5,"title":"Test Title","reading_time":3.0}],"links":{"first":"\/?page=1","last":"\/?page=1","prev":null,"next":null},"meta":{"current_page":1,"from":1,"last_page":1,"links":[{"url":null,"label":"« Previous","page":null,"active":false},{"url":"\/?page=1","label":"1","page":1,"active":true},{"url":null,"label":"Next »","page":null,"active":false}],"path":"\/","per_page":15,"to":1,"total":10}}',
905905
$response->baseResponse->content()
906906
);
907907
}

0 commit comments

Comments
 (0)