Skip to content
This repository was archived by the owner on Nov 14, 2020. It is now read-only.

Commit 040da77

Browse files
committed
Fix transformer
1 parent 0a6b0eb commit 040da77

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Laravel5_Api/Transformers/Transformer.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ public function transformAny($thing)
124124
$transformer = $this->model_mapping->getTransformerFor(get_class($thing));
125125

126126
return $transformer->transform($thing);
127-
} elseif ($thing instanceof Collection and $thing->count() > 0) {
128-
$transformer = $this->model_mapping->getTransformerFor(get_class($thing->first()));
129-
130-
return $thing->map(function ($model) use ($transformer) {
131-
return $transformer->transform($model);
132-
})->toArray();
127+
} elseif ($thing instanceof Collection) {
128+
return $thing->map(function ($item) {
129+
return $this->transformAny($item);
130+
});
131+
} elseif (is_array($thing)) {
132+
return array_map(function ($item) {
133+
return $this->transformAny($item);
134+
}, $thing);
133135
}
134136

135137
return $thing;
@@ -182,6 +184,7 @@ protected function alias()
182184
*/
183185
protected function beforeSerialize()
184186
{
187+
//
185188
}
186189

187190
/**

0 commit comments

Comments
 (0)