@@ -283,42 +283,37 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
283
283
284
284
$ perPage = $ perPage ?: $ this ->model ->getPerPage ();
285
285
286
- // $results = ($total = $this->toBase()->getCountForPagination())
287
- // ? $this->forPage($page, $perPage)->get($columns)
288
- // : $this->model->newCollection();
289
-
290
286
/** @var FMBaseBuilder $query */
291
- $ query = $ this ->getQuery ()->forPage ($ page , $ perPage );
292
-
287
+ $ query = $ this ->toBase ()->forPage ($ page , $ perPage );
293
288
294
289
// prep items and total as null so we can handle 401 errors
295
-
296
290
$ total = null ;
297
- $ items = null ;
291
+ $ results = null ;
292
+
298
293
// do the query and check for a 401. The query will 401 error if there are no rows which match the request
299
294
try {
300
295
$ response = $ this ->getQuery ()->getConnection ()->performFind ($ query );
301
296
} catch (FileMakerDataApiException $ e ) {
302
297
if ($ e ->getCode () == 401 ) {
303
- $ items = collect ([] );
298
+ $ results = $ this -> model -> newCollection ( );
304
299
$ total = 0 ;
305
300
} else {
306
301
throw $ e ;
307
302
}
308
303
}
309
304
310
305
// We didn't get a 401 and have received a real response, so parse it for the paginator
311
- if ($ total === null && $ items === null ) {
306
+ if ($ total === null && $ results === null ) {
312
307
313
308
$ total = $ response ['response ' ]['dataInfo ' ]['foundCount ' ];
314
309
315
310
$ records = collect ($ response ['response ' ]['data ' ]);
316
311
317
312
// start items as an empty array, but fill if the records
318
- $ items = $ this ->model ->createModelsFromRecordSet ($ records );
313
+ $ results = $ this ->model ->createModelsFromRecordSet ($ records );
319
314
}
320
315
321
- return $ this ->paginator ($ items , $ total , $ perPage , $ page , [
316
+ return $ this ->paginator ($ results , $ total , $ perPage , $ page , [
322
317
'path ' => Paginator::resolveCurrentPath (),
323
318
'pageName ' => $ pageName ,
324
319
]);
@@ -381,4 +376,4 @@ protected function getOnlyModifiedPortalFields($array1, $array2): array
381
376
}
382
377
383
378
384
- }
379
+ }
0 commit comments