Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -489,21 +489,30 @@ $tree = Category::descendantsOf($rootId)->toTree($rootId);

### Deleting nodes

To delete a node:
#### To delete a node:

```php
$node->delete();
```

**IMPORTANT!** Any descendant that node has will also be deleted!
> [!IMPORTANT]
> Any descendant that node will also be deleted!

**IMPORTANT!** Nodes are required to be deleted as models, **don't** try do delete them using a query like so:
#### To delete multiple nodes:

```php
Category::where('id', '=', $id)->delete();
$nodes = Model::query()->get();
foreach ($nodes as $node) {
$node->fresh()?->delete(); // Reload the `_lft` & `_rgt` columns using `fresh` method
}
```

This will break the tree!
> [!IMPORTANT]
> Node are required to be deleted as models, **don't** try do delete them using a query like so:
> ```php
> Category::where('id', '=', $id)->delete();
> ```
>
>This will break the tree!

`SoftDeletes` trait is supported, also on model level.

Expand Down