Happy Coder
Happy Coder

Reputation: 4682

Fractal Transform nested array in Laravel

I have a hierarchical array which has the parent child relation. Now when I try to transform it, the transformation is happening only on one level. My array looks like following :

Array
(
    [0] => stdClass Object
        (
            [id] => 4
            [parent_uuid] => 
            [name] => Users
            [placement] => 1
            [children] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 1
                            [parent_uuid] => 4
                            [name] => User Profile
                            [placement] => 1
                            [children] => Array
                                (
                                    [2] => stdClass Object
                                        (
                                            [id] => 7
                                            [parent_uuid] => 1
                                            [name] => Test Page
                                            [placement] => 1
                                        )

                                )

                        )

                )

        )

)

I am using fractal transformers, but the problem is after transforming, I am getting only the first children as the transformers will not look into the nested array. How can I make the transformer look into nested array ?

Upvotes: 1

Views: 1028

Answers (1)

Happy Coder
Happy Coder

Reputation: 4682

This can be achieved by using default includes. We need to have the children as default includes in the first tree transformer and should do the same in Child transformer also.

Upvotes: 2

Related Questions