22
33namespace Yajra \DataTables \Transformers ;
44
5+ use Illuminate \Support \Collection as LaravelCollection ;
56use League \Fractal \Manager ;
67use League \Fractal \Resource \Collection ;
78use League \Fractal \Serializer \SerializerAbstract ;
@@ -17,7 +18,7 @@ class FractalTransformer
1718 /**
1819 * FractalTransformer constructor.
1920 *
20- * @param \League\Fractal\Manager $fractal
21+ * @param \League\Fractal\Manager $fractal
2122 */
2223 public function __construct (Manager $ fractal )
2324 {
@@ -27,24 +28,27 @@ public function __construct(Manager $fractal)
2728 /**
2829 * Transform output using the given transformer and serializer.
2930 *
30- * @param array $output
31+ * @param array|\Illuminate\Support\Collection $output
3132 * @param iterable $transformer
3233 * @param SerializerAbstract|null $serializer
3334 * @return array
3435 */
35- public function transform (array $ output , iterable $ transformer , SerializerAbstract $ serializer = null ): array
36- {
36+ public function transform (
37+ array |LaravelCollection $ output ,
38+ iterable $ transformer ,
39+ SerializerAbstract $ serializer = null
40+ ): array {
3741 if ($ serializer !== null ) {
3842 $ this ->fractal ->setSerializer ($ this ->createSerializer ($ serializer ));
3943 }
4044
4145 $ collector = [];
4246 foreach ($ transformer as $ transform ) {
4347 if ($ transform != null ) {
44- $ resource = new Collection ($ output , $ this ->createTransformer ($ transform ));
45- $ collection = $ this ->fractal ->createData ($ resource )->toArray ();
46- $ transformed = $ collection ['data ' ] ?? $ collection ;
47- $ collector = array_map (
48+ $ resource = new Collection ($ output , $ this ->createTransformer ($ transform ));
49+ $ collection = $ this ->fractal ->createData ($ resource )->toArray ();
50+ $ transformed = $ collection ['data ' ] ?? $ collection ;
51+ $ collector = array_map (
4852 function ($ item_collector , $ item_transformed ) {
4953 if (! is_array ($ item_collector )) {
5054 $ item_collector = [];
0 commit comments