diff --git a/src/Transformer.php b/src/Transformer.php index fbe77ed8c..bdf52384a 100644 --- a/src/Transformer.php +++ b/src/Transformer.php @@ -91,10 +91,10 @@ public function transform($class, $transformer) */ public function transformResponse($response) { - $transformer = $this->resolveTransformer($this->getTransformer($response)); - $this->setRequestedScopes(); + $transformer = $this->resolveTransformer($this->getTransformer($response)); + $resource = $this->createResource($response, $transformer); // If the response is a paginator then we'll create a new paginator @@ -197,6 +197,11 @@ protected function getTransformer($class) */ protected function hasTransformer($class) { + if ($this->isCollection($class)) + { + $class = $class->first(); + } + $class = is_object($class) ? get_class($class) : $class; return isset($this->transformers[$class]); diff --git a/tests/TransformerTest.php b/tests/TransformerTest.php index 392256168..2456e7071 100644 --- a/tests/TransformerTest.php +++ b/tests/TransformerTest.php @@ -35,8 +35,10 @@ public function testDeterminingIfResponseIsTransformable() $this->assertFalse($this->transformer->transformableResponse(true)); $this->assertFalse($this->transformer->transformableResponse(false)); $this->assertFalse($this->transformer->transformableResponse(31.1)); + $this->assertFalse($this->transformer->transformableResponse(new Illuminate\Support\Collection([new Foo, new Foo]))); $this->transformer->transform('Foo', 'Bar'); $this->assertTrue($this->transformer->transformableResponse('Foo')); + $this->assertTrue($this->transformer->transformableResponse(new Illuminate\Support\Collection([new Foo, new Foo]))); }