Skip to content

Commit

Permalink
Add tree chaperoning to the readme (#264)
Browse files Browse the repository at this point in the history
* Add tree chaperoning to the readme

* Apply review suggestion

Co-authored-by: Jonas Staudenmeir <[email protected]>

---------

Co-authored-by: Jonas Staudenmeir <[email protected]>
  • Loading branch information
SanderMuller and staudenmeir authored Oct 8, 2024
1 parent 1afe377 commit c47a8be
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ $tree = User::tree(3)->get();
$tree = User::treeOf($constraint, 3)->get();
```

You can also chaperone tree relations to load parent/ancestor relations already present in the tree to (potentially) reduce 1+n queries:

```php
$tree = User::tree(3)->get();

$tree->loadTreePathRelations();
```

Or via `toTree`:

```php
$users = User::tree(1)->get();

$tree = $users->loadTreePathRelations()->toTree();
```

#### Filters

The trait provides query scopes to filter models by their position in the tree:
Expand Down

0 comments on commit c47a8be

Please sign in to comment.