oddvalue/laravel-drafts
Drop-in drafts and revisions for Laravel Eloquent models. Create, save, publish, and preview revisions with a simple API, middleware support, and minimal setup—ideal for CMS-style editing workflows without building a custom versioning system.
Start by installing the package via Composer and publishing the config file to customize column names and revision limits. Then add the HasDrafts trait to any model requiring draft support. The package automatically adds required columns (is_current, is_published, published_at, uuid, etc.) via a migration helper — use $table->drafts() in your schema definition. For new models, drafts are optional: call createDraft(), saveAsDraft(), or explicitly set is_published => false. Published records are returned by default due to a global scope, but withDrafts() and current() scopes allow flexible retrieval.
current() scope to show the latest working version (draft or published), and expose is_published toggling to let authors preview or publish changes.WithDraftsMiddleware or use Route::withDrafts() to temporarily bypass the published-only global scope.Post::current()->where('author_id', $id)->get() to manage author-specific drafts.$draftableRelations (or override getDraftableRelations()) on the model to auto-duplicate/sync HasOne, HasMany, BelongsToMany, and MorphToMany relations during publish.$model->revisions() to walk through change history; leverage the keep config to auto-cleanup old revisions (default 10).withoutRevision() when updating without generating new revisions (e.g., soft delete cleanup, system updates).Post::withoutDrafts()->get() when debugging unexpected query results.uuid uniqueness before enabling drafts — consider seeding UUIDs first.IS_PUBLISHED or PUBLISHER_MORPH_NAME, ensure the migration columns match exactly. Using $table->drafts() helps avoid mismatches.WithDraftsMiddleware only affects the current request — don’t rely on it across jobs or queue workers; use LaravelDrafts::previewMode() manually there.BelongsToMany relations are synced on publish, so any detachments on the draft won’t affect the published model until publish — consider pre-syncing or explicit detach logic if needed.How can I help you explore Laravel packages today?