Skip to content

Saving ​

update() saves the record with what the form submitted and everybody's latest edits:

php
$post->collaboration()->update($validated);

When somebody else saves, every open form hears it ("Bob saved"). Live fields already show everybody's edits. Other fields take the saved values if this person hasn't changed them. Livewire, React and Vue all do this for you.

When two people change the same field, outside the live fields, the second save stops with a message on the field: "Bob also changed Category. Choose which version to keep, then save again." Show the choice with <Conflicts form={form} /> (React), <Conflicts :form="form" /> (Vue) or <x-collaboration::conflicts :conflicts="$collaborationConflicts" /> (Livewire). A field only one of them changed keeps that change: a stale form never overwrites what somebody else saved.

When saving is more than an update, use save() with a closure. It receives the merged values:

php
$post->collaboration()->save($validated, function (array $values) use ($post) {
    $post->fill($values)->publish();
});

Live fields come from the shared draft, which holds everybody's edits up to this moment, so a stale form can't overwrite someone else's typing. Other fields are saved as submitted. Everybody in the room then hears that the record was saved, and by whom.

The form sends its unsynced edits in a _collaboration input; useCollaborativeForm() and saveCollaboratively() add it for you. A form that was never live (no JavaScript, an API client) simply overwrites, like any other save.

Saves of one record are serialised with a cache lock, so two people pressing Save together both succeed, one after the other.

Released under the MIT License.