|
9 | 9 | use Illuminate\Contracts\Support\Arrayable;
|
10 | 10 | use Illuminate\Database\Eloquent\Builder;
|
11 | 11 | use Illuminate\Pagination\Paginator;
|
| 12 | +use Illuminate\Support\Arr; |
12 | 13 | use Illuminate\Support\Collection;
|
13 | 14 |
|
14 | 15 | class FMEloquentBuilder extends Builder
|
@@ -194,7 +195,6 @@ public function editRecord()
|
194 | 195 | $this->model->setModId($this->getModIdFromFmResponse($response));
|
195 | 196 | }
|
196 | 197 |
|
197 |
| - |
198 | 198 | // also update any container fields which have changed
|
199 | 199 | // Only attempt to write modified container fields
|
200 | 200 | $modifiedContainerFields = $this->model->getContainersToWrite();
|
@@ -258,35 +258,12 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
|
258 | 258 |
|
259 | 259 | $perPage = $perPage ?: $this->model->getPerPage();
|
260 | 260 |
|
261 |
| - /** @var FMBaseBuilder $query */ |
262 |
| - $query = $this->toBase()->forPage($page, $perPage); |
263 |
| - |
264 |
| - // prep items and total as null so we can handle 401 errors |
265 |
| - $total = null; |
266 |
| - $results = null; |
267 |
| - |
268 |
| - // do the query and check for a 401. The query will 401 error if there are no rows which match the request |
269 |
| - try { |
270 |
| - $response = $this->getQuery()->getConnection()->performFind($query); |
271 |
| - } catch (FileMakerDataApiException $e) { |
272 |
| - if ($e->getCode() == 401) { |
273 |
| - $results = $this->model->newCollection(); |
274 |
| - $total = 0; |
275 |
| - } else { |
276 |
| - throw $e; |
277 |
| - } |
278 |
| - } |
279 |
| - |
280 |
| - // We didn't get a 401 and have received a real response, so parse it for the paginator |
281 |
| - if ($total === null && $results === null) { |
282 |
| - |
283 |
| - $total = $response['response']['dataInfo']['foundCount']; |
| 261 | + $response = $this->forPage($page, $perPage)->getData(); |
284 | 262 |
|
285 |
| - $records = collect($response['response']['data']); |
286 |
| - |
287 |
| - // start items as an empty array, but fill if the records |
288 |
| - $results = $this->model->createModelsFromRecordSet($records); |
289 |
| - } |
| 263 | + $total = Arr::get($response, 'response.dataInfo.foundCount', 0); |
| 264 | + $results = $this->model->createModelsFromRecordSet( |
| 265 | + collect(Arr::get($response, 'response.data')) |
| 266 | + ); |
290 | 267 |
|
291 | 268 | return $this->paginator($results, $total, $perPage, $page, [
|
292 | 269 | 'path' => Paginator::resolveCurrentPath(),
|
|
0 commit comments