You can create categories using the rinvex.categories.category service.
Creating a Root Category
By default, creating a category without specifying a parent appends it to the end of the tree as a root.
Making an existing category a root
You can move an existing category to the root level using saveAsRoot() (implicit save) or makeRoot()->save() (explicit save).
Appending/Prepending to a parent
To make a category a child of an existing $parent category:
- Append (last child): Use
appendToNode($parent)->save(), $parent->appendNode($category), or $category->parent()->associate($parent)->save(). - Prepend (first child): Use
prependToNode($parent)->save() or $parent->prependNode($category).
Inserting relative to a neighbor
You can position a category before or after a specific $neighbor category:
- Explicit save:
$category->afterNode($neighbor)->save() or $category->beforeNode($neighbor)->save(). - Implicit save:
$category->insertAfterNode($neighbor) or $category->insertBeforeNode($neighbor).
// Create as root
app('rinvex.categories.category')->create($attributes);
// Append to parent
$category->appendToNode($parent)->save();
// Prepend to parent
$category->prependToNode($parent)->save();
// Insert after neighbor
$category->afterNode($neighbor)->save();