Drafts, revisions and the trash
Changes that wait until they are published, the versions a publish replaced, and the way back from a delete.
The entry's own row is always what is live, so a visitor's read is the same single-row select whether or not someone is working on the page. What an editor is working on waits beside it as a draft.
Drafts
$draft = Mainstay::drafts()->save(Article::class, ['title' => 'A better title'], entry: 5);
Mainstay::drafts()->publish($draft->id);
A draft holds only what differs from what is live. Each key saved is compared with the live value and kept only where it differs, so a form posting every field leaves a draft of what was changed, and a draft left changing nothing is deleted. An entry has one draft at a time; saving again merges into it. A draft may be incomplete: what it holds is checked as a write is, but a required field may wait until publish.
Without entry:, the draft is of a new entry, which has no row, id or path until it is published. find(), of() and all() read drafts back, and discard() drops one.
Publishing
Publish puts a draft live in one transaction: each language it holds is validated as an update is, written, and the outgoing version is filed as a revision, then the draft is deleted. Publishing is its own capability, so a role can write drafts for someone else to publish. Mainstay::create() and update() write live directly and ask for publish too.
Revisions
Every version a publish, or a live write, replaced is kept as a revision, newest first, up to revisions in the config, 50 by default; null keeps every one. Restoring one makes it the entry's draft, which goes live through publish like any other:
$revisions = Mainstay::revisions()->of(Article::class, 5);
Mainstay::revisions()->restore($revisions->first()->id);
The admin's history lists them with who published each.
The trash
delete() moves an entry to the trash in every language at once, and its path stops answering in the same request. Relations to it read as missing while it is there.
Mainstay::restore(Article::class, 5);
Mainstay::destroy(Article::class, 5);
restore() builds its paths again; where one was taken while it was away, its slug takes the first of -2, -3 that frees it. destroy() erases it for good, from the trash only, with its draft, its revisions and its terms.
Hearing about changes
Saved, Published, Deleted and Restored, in Mainstay\Events, carry the type and id of live content written. They are dispatched once the write commits, never when it rolls back. Listen with Event::listen to clear a cache or ping a build.