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.
Strengths:
HasDrafts) and integrates seamlessly with existing Laravel models, requiring minimal architectural changes.withoutDrafts(), withDrafts(), onlyDrafts()) align with Laravel’s Eloquent conventions, reducing cognitive load for developers.HasOne, HasMany, BelongsToMany, and MorphToMany relations, making it versatile for complex models.Weaknesses:
is_current, is_published, uuid, etc.) per model, which may not align with existing schemas or microservices architectures.Laravel Ecosystem Fit:
WithDraftsMiddleware enables granular route-level access control for drafts, useful for admin panels.composer test command, easing CI/CD integration.Non-Laravel Systems:
Database Compatibility:
| Risk Area | Severity | Mitigation |
|---|---|---|
| Schema Migration | High | Requires backward-compatible migrations (e.g., drafts() helper). Test in staging first. |
| Performance with Revisions | Medium | Monitor query performance; consider archiving old revisions via a cron job. |
| Relation Sync Complexity | Medium | Test thoroughly with polymorphic/many-to-many relations. |
| Preview Mode Leaks | Low | Ensure middleware/preview mode is disabled in production routes. |
| Laravel Version Lock | Low | Package supports LTS versions (9–13); align with your Laravel upgrade cycle. |
Database Strategy:
revisions table?Workflow Requirements:
author_id, change_description)?Performance:
Deployment:
Alternatives:
spatie/laravel-activitylog for revisions, or custom solutions)?Primary Fit:
Partial Fit:
Non-Fit:
Assessment Phase:
Post, Page, Product).uuid() columns without downtime?).Pilot Implementation:
Post) to test:
use HasDrafts).tags for a blog post).Incremental Rollout:
MorphToMany).Database Migration:
drafts() schema helper to add columns in a single migration:
Schema::table('posts', function (Blueprint $table) {
$table->drafts();
});
Laravel Versions:
v3.x) for bug fixes and Laravel 13 support.PHP Versions:
composer.json for exact ranges).Dependencies:
illuminate/contracts).MediaLibrary, ActivityLog) if relations are marked as draftable.Pre-requisites:
Installation Order:
composer require oddvalue/laravel-drafts
php artisan vendor:publish --tag="drafts-config"
config/drafts.php (e.g., adjust revisions.keep or column names).Model Integration:
HasDrafts trait to target models.$draftableRelations for models with relations.API/Route Integration:
WithDraftsMiddleware to admin routes.Testing:
createDraft, saveAsDraft, revisions).Monitoring:
SELECT COUNT(*) FROM posts WHERE is_published = 0).config/drafts.php for easy adjustments (e.gHow can I help you explore Laravel packages today?