Skip to content

Commit ed90638

Browse files
author
David Nahodyl
committed
fixed global scopes not applying on paginator
1 parent 1c9f3e3 commit ed90638

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/Database/Eloquent/FMEloquentBuilder.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,42 +283,37 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
283283

284284
$perPage = $perPage ?: $this->model->getPerPage();
285285

286-
// $results = ($total = $this->toBase()->getCountForPagination())
287-
// ? $this->forPage($page, $perPage)->get($columns)
288-
// : $this->model->newCollection();
289-
290286
/** @var FMBaseBuilder $query */
291-
$query = $this->getQuery()->forPage($page, $perPage);
292-
287+
$query = $this->toBase()->forPage($page, $perPage);
293288

294289
// prep items and total as null so we can handle 401 errors
295-
296290
$total = null;
297-
$items = null;
291+
$results = null;
292+
298293
// do the query and check for a 401. The query will 401 error if there are no rows which match the request
299294
try {
300295
$response = $this->getQuery()->getConnection()->performFind($query);
301296
} catch (FileMakerDataApiException $e) {
302297
if ($e->getCode() == 401) {
303-
$items = collect([]);
298+
$results = $this->model->newCollection();
304299
$total = 0;
305300
} else {
306301
throw $e;
307302
}
308303
}
309304

310305
// 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) {
312307

313308
$total = $response['response']['dataInfo']['foundCount'];
314309

315310
$records = collect($response['response']['data']);
316311

317312
// start items as an empty array, but fill if the records
318-
$items = $this->model->createModelsFromRecordSet($records);
313+
$results = $this->model->createModelsFromRecordSet($records);
319314
}
320315

321-
return $this->paginator($items, $total, $perPage, $page, [
316+
return $this->paginator($results, $total, $perPage, $page, [
322317
'path' => Paginator::resolveCurrentPath(),
323318
'pageName' => $pageName,
324319
]);
@@ -381,4 +376,4 @@ protected function getOnlyModifiedPortalFields($array1, $array2): array
381376
}
382377

383378

384-
}
379+
}

0 commit comments

Comments
 (0)