diff --git a/composer.json b/composer.json index 939f729..a00a4c6 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": "^7.2.5", "nesbot/carbon": "^1.26.3 || ^2.0", - "guzzlehttp/guzzle": "~6.0|~5.0|~4.0", + "guzzlehttp/guzzle": "~7.0|~6.0|~5.0|~4.0", "firebase/php-jwt": "^5.0", "illuminate/support": "^7.0", "macsidigital/laravel-oauth2-client": "^1.0" @@ -25,7 +25,7 @@ "require-dev": { "orchestra/testbench": "^5.0", "phpunit/phpunit": "^8.5" - }, + }, "autoload": { "psr-4": { "MacsiDigital\\API\\": "src" @@ -50,7 +50,7 @@ "MacsiDigital\\API\\Providers\\APIServiceProvider" ], "aliases": { - + } } } diff --git a/src/Support/Builder.php b/src/Support/Builder.php index cfcd43b..6dc211a 100644 --- a/src/Support/Builder.php +++ b/src/Support/Builder.php @@ -273,7 +273,7 @@ public function all() } - public function get() + public function get($type = 'get') { if($this->resource->beforeQuery($this) === false){ return; @@ -281,18 +281,12 @@ public function get() return $this->handleResponse($this->sendRequest('get', [ $this->retreiveEndPoint('get'), $this->addPagination($this->combineQueries()) - ]), 'get'); + ]), $type); } public function getOne() { - if($this->resource->beforeQuery($this) === false){ - return; - } - return $this->handleResponse($this->sendRequest('get', [ - $this->retreiveEndPoint('get'), - $this->addPagination($this->combineQueries()) - ]), 'individual'); + return $this->get('individual'); } public function post($attributes, $type="individual") diff --git a/src/Support/ResultSet.php b/src/Support/ResultSet.php index 736ac7e..df08ed0 100644 --- a/src/Support/ResultSet.php +++ b/src/Support/ResultSet.php @@ -116,10 +116,12 @@ protected function populate($array) $this->incrementTotalDownloads(count($array[$this->resource->getApiMultipleDataField()])); return $this; } else{ - foreach($array[$this->resource->getApiMultipleDataField()] as $object){ - $this->items->push($this->resource->newFromBuilder($this->resource->passOnAttributes($object))); - $this->incrementTotalDownloads(); - } + if(isset($array[$this->resource->getApiMultipleDataField()])){ + foreach($array[$this->resource->getApiMultipleDataField()] as $object){ + $this->items->push($this->resource->newFromBuilder($this->resource->passOnAttributes($object))); + $this->incrementTotalDownloads(); + } + } } } diff --git a/src/Traits/InteractsWithAPI.php b/src/Traits/InteractsWithAPI.php index f997fd0..3c87692 100644 --- a/src/Traits/InteractsWithAPI.php +++ b/src/Traits/InteractsWithAPI.php @@ -387,7 +387,7 @@ protected function performUpdate(Builder $query) } $resource = (new $this->updateResource)->fill($this, 'update'); - + if($resource->getAttributes() != []){ $validator = $resource->validate(); @@ -613,6 +613,11 @@ public function fresh() return; } + if(method_exists($this, 'find')) + { + return $this->find($this->getKey()); + } + return $this->newQuery()->find($this->getKey()); }