diff --git a/src/Forge.php b/src/Forge.php index fc80b96..64654cb 100644 --- a/src/Forge.php +++ b/src/Forge.php @@ -4,6 +4,7 @@ use GuzzleHttp\Client as HttpClient; use Laravel\Forge\Resources\User; +use Exception; class Forge { @@ -76,6 +77,12 @@ public function __construct($apiKey = null, ?HttpClient $guzzle = null) */ protected function transformCollection($collection, $class, $extraData = []) { + if (!is_array($collection)) { + throw new Exception( + "Unexpected response format. Expected an array, got " . gettype($response) + ); + } + return array_map(function ($data) use ($class, $extraData) { return new $class($data + $extraData, $this); }, $collection);