labrodev-viewmodel-resourcelisted
Install: claude install-skill labrodev/laravel-playbook
# ViewModels & Resources — the presentation boundary
Part of the Labrodev playbook. **The law for this component lives in the always-on `labrodev-viewmodel-resource` guideline** (musts, must-nots); the per-file checklist is `rules/viewmodels-resources.md`. This skill holds the craft: anatomy, canonical templates, and edge cases.
Together these two classes form the security boundary between the database and the browser:
- The **ViewModel** decides *which* data reaches the page (which models, which relations, which options).
- The **Resource** decides *what fields* of that data are exposed (an explicit allowlist).
Neither may be bypassed. Raw Eloquent models never reach Inertia or JSON output.
## Responsibility split (controller vs ViewModel vs Resource)
| Concern | Owner |
|---|---|
| Authorize, run the primary IndexQuery, paginate, construct ViewModel, `Inertia::render(...)` | Controller → see the labrodev-controller skill |
| Collect **all remaining page data**: auxiliary lists, select options, flags, counts — via Query classes | ViewModel (`App/Layer/{Layer}/{Domain}/ViewModels`) |
| Shape the props: pagination envelope, resolved Resources | ViewModel |
| Allowlist mapping of a single model to public fields | Resource (`App/Layer/{Layer}/{Domain}/Resources`) |
| Business rules, mutations, workflows | Never here → see the labrodev-action skill |
The controller hands the ViewModel the primary subject and nothing else. When the template needs more — a project dropdown,