protected function getChildren($collection, $id)
    {
        $parentField = $this->repository->getParentField();
        $result = [];
        foreach ($collection as $instance) {
            if ((int) $instance->$parentField != $id) {
                continue;
            }

            $instance->setRelation(
                'children',
                $this->getChildren($collection, $instance->getKey())
            );

            $result[] = $instance;
        }

        return new Collection($result);
    }
protected function getChildren($collection, $id)
    {
        $parentField = $this->repository->getParentField();
        $result = [];
        foreach ($collection as $instance) {
            if ((int) $instance->$parentField != $id) {
                continue;
            }

            $instance->setRelation(
                'children',
                $this->getChildren($collection, $instance->getKey())
            );

            $result[] = $instance;
        }

        return new Collection($result);
    }
protected function getChildren ( $ collection , $ id ) { $ parentField = $ this -> repository -> getParentField ( ) ; $ result = [ ] ; foreach ( $ collection as $ instance ) { if ( ( int ) $ instance -> $ parentField != $ id ) { continue ; } $ instance -> setRelation ( 'children' , $ this -> getChildren ( $ collection , $ instance -> getKey ( ) ) ) ; $ result [ ] = $ instance ; } return new Collection ( $ result ) ; }
Get children for simple tree type structure.

@param $collection
@param $id

@return Collection
Get children for simple tree type structure .