diff --git a/src/Transformer/Factory.php b/src/Transformer/Factory.php index 388039d81..c714e19b5 100644 --- a/src/Transformer/Factory.php +++ b/src/Transformer/Factory.php @@ -175,6 +175,11 @@ protected function hasBinding($class) */ protected function boundByContract($class) { + if ($this->isCollection($class)) + { + return is_object($class->first()) and $class->first() instanceof TransformableInterface; + } + return is_object($class) and $class instanceof TransformableInterface; } diff --git a/tests/TransformerFactoryTest.php b/tests/TransformerFactoryTest.php index 15b623d7a..2daf6614e 100644 --- a/tests/TransformerFactoryTest.php +++ b/tests/TransformerFactoryTest.php @@ -39,7 +39,7 @@ public function testDeterminingIfResponseIsTransformable() $this->transformerFactory->transform('Foo', 'FooTransformerStub'); $this->assertTrue($this->transformerFactory->transformableResponse('Foo')); $this->assertTrue($this->transformerFactory->transformableResponse(new Bar)); - $this->assertTrue($this->transformerFactory->transformableResponse(new Illuminate\Support\Collection([new Foo, new Foo]))); + $this->assertTrue($this->transformerFactory->transformableResponse(new Illuminate\Support\Collection([new Bar, new Bar]))); }