9 months ago

How to get all children recursively?

Posted 9 months ago by knubbe82

I am trying to get all children of model recursively but can't get children of children. This is what I have:

public function children()
        return $this->hasMany('App\Group', 'parent_id', 'id');

I also try this:

public function childrenRecursive()
        return $this->children()->with('childrenRecursive');

In both cases when I use $group->children or $group->childrenRecursive() I get only children but not children of children.

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