GeorgeW
127
2
Laravel

Recursive Tags

Posted 1 month ago by GeorgeW

Hello,

So i have a tags model which has a parent_id, the relationships are Parent and Child.

so a Tag can have another Tag->id as its Parent_id.

I need a way to build a resource response as follows:

            'id' => $item['id'],
            'text' => $item['name'],
            'children' => [
                     'id' => $item['id'],
             'text' => $item['name'],
             'children' => [
                         'id' => $item['id'],
                 'text' => $item['name'],
                'children' => [
                
                     ]
                  ]
            ]
       

This needs to be recursive as there could be infinite number of children.

Any suggestions arew welcome.

Please sign in or create an account to participate in this conversation.