@@ -164,7 +164,7 @@ protected function searchWhereInternal($term, $columns, $mode, $boolean)
164
164
* @param int $page
165
165
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
166
166
*/
167
- public function paginate ($ perPage = null , $ columns = ['* ' ], $ pageName = 'page ' , $ page = null )
167
+ public function paginate ($ perPage = null , $ columns = ['* ' ], $ pageName = 'page ' , $ page = null , $ total = null )
168
168
{
169
169
// Legacy signature support
170
170
// paginate($perPage, $page, $columns, $pageName)
@@ -178,18 +178,17 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
178
178
$ page = is_array ($ _currentPage ) ? null : $ _currentPage ;
179
179
}
180
180
181
- if (!$ page ) {
182
- $ page = Paginator::resolveCurrentPage ($ pageName );
183
- }
181
+ $ page = $ page ?: Paginator::resolveCurrentPage ($ pageName );
184
182
185
- if (!$ perPage ) {
186
- $ perPage = $ this ->model ->getPerPage ();
187
- }
183
+ $ total = value ($ total ) ?? $ this ->toBase ()->getCountForPagination ();
188
184
189
- $ total = $ this ->toBase ()->getCountForPagination ();
190
- $ this ->forPage ((int ) $ page , (int ) $ perPage );
185
+ $ perPage = value ($ perPage , $ total ) ?: $ this ->model ->getPerPage ();
191
186
192
- return $ this ->paginator ($ this ->get ($ columns ), $ total , $ perPage , $ page , [
187
+ $ results = $ total
188
+ ? $ this ->forPage ($ page , $ perPage )->get ($ columns )
189
+ : $ this ->model ->newCollection ();
190
+
191
+ return $ this ->paginator ($ results , $ total , $ perPage , $ page , [
193
192
'path ' => Paginator::resolveCurrentPath (),
194
193
'pageName ' => $ pageName
195
194
]);
@@ -204,31 +203,27 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
204
203
* @param int $currentPage
205
204
* @return \Illuminate\Contracts\Pagination\Paginator
206
205
*/
207
- public function simplePaginate ($ perPage = null , $ columns = ['* ' ], $ pageName = 'page ' , $ currentPage = null )
206
+ public function simplePaginate ($ perPage = null , $ columns = ['* ' ], $ pageName = 'page ' , $ page = null )
208
207
{
209
208
// Legacy signature support
210
209
// paginate($perPage, $currentPage, $columns, $pageName)
211
210
if (!is_array ($ columns )) {
212
211
$ _currentPage = $ columns ;
213
212
$ _columns = $ pageName ;
214
- $ _pageName = $ currentPage ;
213
+ $ _pageName = $ page ;
215
214
216
215
$ columns = is_array ($ _columns ) ? $ _columns : ['* ' ];
217
216
$ pageName = $ _pageName !== null ? $ _pageName : 'page ' ;
218
- $ currentPage = is_array ($ _currentPage ) ? null : $ _currentPage ;
217
+ $ page = is_array ($ _currentPage ) ? null : $ _currentPage ;
219
218
}
220
219
221
- if (!$ currentPage ) {
222
- $ currentPage = Paginator::resolveCurrentPage ($ pageName );
223
- }
220
+ $ page = $ page ?: Paginator::resolveCurrentPage ($ pageName );
224
221
225
- if (!$ perPage ) {
226
- $ perPage = $ this ->model ->getPerPage ();
227
- }
222
+ $ perPage = $ perPage ?: $ this ->model ->getPerPage ();
228
223
229
- $ this ->skip (($ currentPage - 1 ) * $ perPage )->take ($ perPage + 1 );
224
+ $ this ->skip (($ page - 1 ) * $ perPage )->take ($ perPage + 1 );
230
225
231
- return $ this ->simplePaginator ($ this ->get ($ columns ), $ perPage , $ currentPage , [
226
+ return $ this ->simplePaginator ($ this ->get ($ columns ), $ perPage , $ page , [
232
227
'path ' => Paginator::resolveCurrentPath (),
233
228
'pageName ' => $ pageName
234
229
]);
0 commit comments