A parent with three states
CheckboxTree::make('departments')->tree(Department::class): checking a parent checks everything under it. A parent is checked when everything under it is, shows a dash when only some of it is, and is empty otherwise.
Note: Try it
The field starts with the Boston office and its three teams checked, so Sales has a dash. Open Sales, then East: East has a dash too, and Boston is checked. Check New York: its three teams are checked with it. Open Boston and uncheck Inside sales: Boston turns from checked to a dash. Then press “Show what would be saved”: it lists the ids of the checked departments (the form saves ids, not names).
Each item on its own
->cascade(false) checks only the item you click. A dash on a parent then means: something under it is checked.
Note: Try it
Open Sales and check East: only East is checked, and Sales gets a dash. Open East: its offices are still unchecked. Check Boston, then uncheck East: Boston stays checked, and East now shows a dash.
A tree written as an array
->tree([...]) takes the items from an array, for example permissions grouped by area. What is saved are the keys of the array.
Note: Try it
Check Orders: View, Edit and Delete under it are checked too. Uncheck Delete: Orders shows a dash. “Show what would be saved” lists the keys, such as orders.view.