Describing a room
$model->collaboration() starts from the model's $collaborative fields. You can describe a room fully in code instead, without the trait:
php
Collaboration::room($post)
->text('title', 'summary')
->rich('body')
->value('status', allowed: PostStatus::class) // refuse values that are not cases
->lock('price', 'slug') // one person at a time
->labels(['body' => 'Article']) // "Alice is in Article"
->locale('fr') // one draft per language
->viewing(); // watch without editingA field cast to an enum only takes its cases, without allowed. A locked field is read-only for everybody else while somebody is in it, and says who: for fields where merging two people's changes makes no sense.
Create pages
Before a record exists there is nothing to merge yet, but people can still see who else is creating one:
php
Inertia::render('Posts/Create', ['collaboration' => Collaboration::creating(Post::class)]);The policy's create ability decides who joins. Use the same components as on an edit page: <Avatars> shows everybody on the create page, and the form saves as usual, with Post::create().
Typos are caught
Everything that can be checked is, as early as possible:
| Mistake | Caught |
|---|---|
'body' => 'richtext' | at once: [richtext] is not a kind of field, for [body]. … Did you mean [rich]? |
->text('titel') | when the page renders, with APP_DEBUG on: [Post] has no attribute [titel] to collaborate on. Did you mean [title]? |
form.field('titel'), <FieldPeople field="titel">, <CollaborativeEditor field="bdy"> | by TypeScript, against the form's own fields |
| A field the room doesn't have, bound in the browser | once, in the console: "titel" is not a field of this room |
A value outside an enum or allowed | refused by the server |