/** * Inserts a node in the database and upates the node's * properties if applicable. * * @param Cartalyst\NestedSets\Nodes\NodeInterface $node * @param Illuminate\Database\Query\Builder $query * @return void */ public function insertNode(NodeInterface $node) { $query = $this->connection->table($this->getTable()); $keyName = $this->baseNode->getKeyName(); $allAttributes = $node->getAllAttributes(); $attributes = array_except($allAttributes, [$this->getDepthAttributeName(), $keyName]); if ($node->getIncrementing()) { $node->setAttribute($keyName, $query->insertGetId($attributes)); } else { $attributes[$keyName] = array_get($allAttributes, $keyName); $query->insert($attributes); } $this->afterCreateNode($node); }