See the demo as…
Everyone in this demo shares one account, so choose here whose eyes to use. A real app writes ->visibleSubtree(fn (User $user) => $user->department_id).
Note: Try it
Choose “Head of East”. The numbers below drop to East and the offices under it. The orders and departments pages change too, until you choose “Everyone” again.
A field limited to what you see
->onlyVisibleSubtree(): the tree starts at your own department, and the server refuses anything outside it.
Note: Try it
As Head of East, open the field: East is the only top-level item. Type “seattle”: nothing is found.
Resources limited to what you see
OrderResource and DepartmentResource use the ScopedToVisibleSubtree trait: lists, filters, edit pages and the tree page show only your branch. An order of another branch is not found even by its URL. The History on the tree page lists only the changes in your branch.
Note: Try it
As Head of East, open the orders: every order belongs to an East office. Open the departments: you can rearrange East, but not move it out. To compare the History: as Everyone, drag one department inside Finance and one inside East on the departments page, then choose Head of East above and press History there. Only the East change is listed.