JJK
2 months ago
232
6
Laravel

Fetching nested groups along with their nested groups.

Posted 2 months ago by JJK

My app is structured as such, so I can load groups as shown below:

A->
    B->
        C

The issue is thought, while I can easily create a recursive children() method that returns children of children of children of .. - the thing complicates when these groups have members, in which case it's (in json terms) as such:

{
    members: [],
    children:
    [
        {
            members: [],
            children:
            [
                {
                    members: [],
                    children:
                    [

                    ]
                }
            ]
        }
    ]
}

I think you get the idea - this one is troublesome because I could technically add $with to the model and be on with it (but it's slow), so I'm looking for other solutions to this mishap :)

Doing ->with(['children', 'children.children', 'children.children' ...] is out of the case lol.

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