src/Franzose/ClosureTable/Models/Entity.php
public static function createFromArray(array $tree, EntityInterface $parent = null)
    {
        $childrenRelationIndex = with(new static)->getChildrenRelationIndex();
        $entities = [];

        foreach ($tree as $item) {
            $children = array_pull($item, $childrenRelationIndex);

            /**
             * @var Entity $entity
             */
            $entity = new static($item);
            $entity->parent_id = $parent ? $parent->getKey() : null;
            $entity->save();

            if (!is_null($children)) {
                $children = static::createFromArray($children, $entity);
                $entity->setRelation($childrenRelationIndex, $children);
                $entity->addChildren($children->all());
            }

            $entities[] = $entity;
        }

        return new Collection($entities);
    }
public static function createFromArray(array $tree, EntityInterface $parent = null)
    {
        $childrenRelationIndex = with(new static)->getChildrenRelationIndex();
        $entities = [];

        foreach ($tree as $item) {
            $children = array_pull($item, $childrenRelationIndex);

            /**
             * @var Entity $entity
             */
            $entity = new static($item);
            $entity->parent_id = $parent ? $parent->getKey() : null;
            $entity->save();

            if (!is_null($children)) {
                $children = static::createFromArray($children, $entity);
                $entity->setRelation($childrenRelationIndex, $children);
                $entity->addChildren($children->all());
            }

            $entities[] = $entity;
        }

        return new Collection($entities);
    }
public static function createFromArray ( array $ tree , EntityInterface $ parent = null ) { $ childrenRelationIndex = with ( new static ) -> getChildrenRelationIndex ( ) ; $ entities = [ ] ; foreach ( $ tree as $ item ) { $ children = array_pull ( $ item , $ childrenRelationIndex ) ; /**
             * @var Entity $entity
             */ $ entity = new static ( $ item ) ; $ entity -> parent_id = $ parent ? $ parent -> getKey ( ) : null ; $ entity -> save ( ) ; if ( ! is_null ( $ children ) ) { $ children = static :: createFromArray ( $ children , $ entity ) ; $ entity -> setRelation ( $ childrenRelationIndex , $ children ) ; $ entity -> addChildren ( $ children -> all ( ) ) ; } $ entities [ ] = $ entity ; } return new Collection ( $ entities ) ; }
Saves models from the given attributes array.

@param array $tree
@param \Franzose\ClosureTable\Contracts\EntityInterface $parent
@return \Franzose\ClosureTable\Extensions\Collection
Saves models from the given attributes array .