Skip to content

Commit

Permalink
Merge pull request #24 from scottcharlesworth/fix-count
Browse files Browse the repository at this point in the history
Fix count method
  • Loading branch information
marcreichel committed Oct 10, 2020
2 parents 067f9f6 + 0978798 commit e8f3e32
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1554,11 +1554,15 @@ public function first()
}

/**
* Return the total "count" result of the query.
*
* @return mixed
* @throws \MarcReichel\IGDBLaravel\Exceptions\MissingEndpointException
* @throws \MarcReichel\IGDBLaravel\Exceptions\MissingEndpointException|AuthenticationException
*/
public function count()
{
$accessToken = $this->retrieveAccessToken();

if ($this->endpoint) {

$this->endpoint = Str::finish($this->endpoint, '/') . 'count';
Expand All @@ -1570,12 +1574,15 @@ public function count()
}

$data = Cache::remember($cacheKey, $this->cacheLifetime,
function () {
function () use ($accessToken) {
try {
return (int)json_decode($this->client->get($this->endpoint,
return (int)json_decode($this->client->post($this->endpoint,
[
'headers' => [
'Authorization' => 'Bearer '.$accessToken,
],
'body' => $this->getQuery(),
])->getBody())['count'];
])->getBody(), true)['count'];
} catch (\Exception $exception) {
$this->handleRequestException($exception);
}
Expand Down

0 comments on commit e8f3e32

Please sign in to comment.