Skip to content

Commit 912e97d

Browse files
author
Michael Deck
committed
Clean up the base builder's count method to use added getData method.
- Also, removed count definition in the eloquent builder because by default any method that does not exist on the eloquent builder is forwarded to the base builder so this definition was duplicated code.
1 parent 4f6dfc9 commit 912e97d

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

src/Database/Eloquent/FMEloquentBuilder.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -271,31 +271,6 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
271271
]);
272272
}
273273

274-
/**
275-
*
276-
* Retrieve the "count" result of the query.
277-
*
278-
* @param string $columns
279-
* @return int
280-
* @throws FileMakerDataApiException
281-
*/
282-
public function count($columns = '*'): int
283-
{
284-
/** @var FMBaseBuilder $query */
285-
$query = $this->query->limit(1);
286-
try {
287-
$response = $this->getQuery()->getConnection()->performFind($query);
288-
$count = $response['response']['dataInfo']['foundCount'];
289-
} catch (FileMakerDataApiException $e) {
290-
if ($e->getCode() == 401) {
291-
$count = 0;
292-
} else {
293-
throw $e;
294-
}
295-
}
296-
return $count;
297-
}
298-
299274
/**
300275
* Compares a model's modified portal data and original portal data and returns portal data with only modified fields and recordIds
301276
*

src/Database/Query/FMBaseBuilder.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -849,22 +849,9 @@ public function setGlobalFields(array $globals)
849849
*/
850850
public function count($columns = '*')
851851
{
852-
$this->limit(1);
853-
try {
854-
$result = $this->connection->performFind($this);
855-
} catch (FileMakerDataApiException $e) {
856-
if ($e->getCode() === 401) {
857-
// no records found - this is ok
858-
// return 0
859-
return 0;
860-
}
861-
862-
// not a 401, so throw it
863-
throw $e;
864-
}
852+
$response = $this->limit(1)->getData();
865853

866-
$count = $result['response']['dataInfo']['foundCount'];
867-
return (int)$count;
854+
return (int)(Arr::get($response, 'response.dataInfo.foundCount', 0));
868855
}
869856

870857
public function whereDate($column, $operator, $value = null, $boolean = 'and')

0 commit comments

Comments
 (0)