PHPackages                             grazulex/laravel-draftable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. grazulex/laravel-draftable

ActiveLibrary[Testing &amp; Quality](/categories/testing)

grazulex/laravel-draftable
==========================

Add drafts, versioning, and publication workflow to any Eloquent model — ideal for content editing, previews, and rollback.

v1.0.0(9mo ago)21194[1 issues](https://github.com/Grazulex/laravel-draftable/issues)MITPHPPHP ^8.3CI passing

Since Aug 8Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/Grazulex/laravel-draftable)[ Packagist](https://packagist.org/packages/grazulex/laravel-draftable)[ Docs](https://github.com/grazulex/laravel-draftable)[ Fund](https://www.buymeacoffee.com/Grazulex)[ Fund](https://paypal.me/strauven)[ RSS](/packages/grazulex-laravel-draftable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Laravel Draftable
=================

[](#laravel-draftable)

 [![Laravel Draftable](new_logo.png)](new_logo.png)**Production-ready drafts, versioning, and publication flow for any Eloquent model**

*A comprehensive package for managing content lifecycle with enterprise-grade quality*

[![Latest Version](https://camo.githubusercontent.com/ef159073007ccc2f993efdc939aef3abe33b3f0c2a6f598d13fc3cb0b36fa4e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a756c65782f6c61726176656c2d647261667461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-draftable)[![Total Downloads](https://camo.githubusercontent.com/8428d9e8e36db67c79ca41d7dc5b6481820b95ca72e61fb7aedc8e9051dab87d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a756c65782f6c61726176656c2d647261667461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-draftable)[![License](https://camo.githubusercontent.com/1b7132ce70a3475b030ed2582afc783d3c483eb2643228ec48dfd38c9a48aa85/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6772617a756c65782f6c61726176656c2d647261667461626c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Grazulex/laravel-draftable/blob/main/LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/e0d7e462e519b2161922d55de0ad2238d79fa8ff673ede65d0f1ddeaf90ec0a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6772617a756c65782f6c61726176656c2d647261667461626c652e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Laravel Version](https://camo.githubusercontent.com/098a1562f4197754b0930358827aeaad3f7c30143bafb8d9633637dc037296a5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31312e782d6666326432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://laravel.com/)[![Tests](https://camo.githubusercontent.com/df74fa7ec436a1f8cc57c0a6c4c66e2182c25cc8edc71fc71cd727ed151ce8e9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d31323825324631323825323070617373696e672d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://github.com/Grazulex/laravel-draftable/actions)[![Coverage](https://camo.githubusercontent.com/1da77fe9b916aa657be2290700eb8f0442890ec82497a6c11221f66ddd079f36/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d39332e362532352d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://github.com/Grazulex/laravel-draftable)[![Code Style](https://camo.githubusercontent.com/161d70e6871f808e0439b3e7a86540993ae98775540b5a2e78226000e3c419c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d70696e742d3030303030303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://github.com/laravel/pint)[![Static Analysis](https://camo.githubusercontent.com/4fec5c7085870aaa2bde8d5c7d722a1fb74a928cac3d9872ee3465858c96183d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d6c6576656c253230352d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://phpstan.org/)

---

🚀 Overview
----------

[](#-overview)

Laravel Draftable is a **production-ready** package that adds comprehensive **drafts**, **versioning**, and **publication workflows** to any Eloquent model in Laravel. Perfect for content management systems, blog platforms, documentation sites, e-commerce products, and any application where you need reliable content lifecycle management with version control capabilities.

✨ Key Features
--------------

[](#-key-features)

- 📝 **Draft System** - Save changes without publishing immediately
- 🕒 **Version History** - Complete tracking of all changes over time
- 🔍 **Version Comparison** - Detailed diff analysis between any versions
- ⏪ **Version Restoration** - Restore to any previous version instantly
- 🚀 **Flexible Publishing** - Manual or automatic publication workflows
- 🗄️ **Storage Strategies** - Same table or separate drafts table support
- 👁️ **Draft Preview** - Preview changes without making them live
- 🔒 **Access Control** - Full Laravel policies integration
- 📊 **Performance Optimized** - Optimized database queries and indexes
- 🎨 **Artisan Commands** - Complete CLI management suite
- 🧪 **Test Coverage** - 128/128 tests passing with 93.6% coverage
- ⚡ **Events System** - Laravel events for draft lifecycle
- 🛡️ **Production Ready** - Zero static analysis errors (PHPStan level 5)

� Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require grazulex/laravel-draftable
```

> **💡 Auto-Discovery**: The service provider will be automatically registered thanks to Laravel's package auto-discovery.

⚡ Quick Start
-------------

[](#-quick-start)

```
use Grazulex\LaravelDraftable\Traits\HasDrafts;

// Add to your model
class Post extends Model
{
    use HasDrafts;

    protected $fillable = ['title', 'content', 'status'];
}

// Create and manage drafts
$post = Post::create(['title' => 'My First Post']);

// Make changes and save as draft
$post->title = 'Updated Title';
$post->content = 'Draft content here...';
$post->saveDraft();

// Publish when ready
$post->publishDraft();

// View version history
$versions = $post->drafts;

// Compare versions using the service
$draftDiff = app(\Grazulex\LaravelDraftable\Services\DraftDiff::class);
$diff = $draftDiff->compare($version1, $version2);

// Restore previous version
$post->restoreVersion(2);
```

🔧 Requirements
--------------

[](#-requirements)

- **PHP 8.2+**
- **Laravel 11.0+**

� Complete Documentation
------------------------

[](#-complete-documentation)

For comprehensive documentation, examples, and advanced usage guides, visit our **Wiki**:

### 📖 **[👉 Laravel Draftable Wiki](https://github.com/Grazulex/laravel-draftable/wiki)**

[](#--laravel-draftable-wiki)

The wiki includes:

- **🏠 [Home](https://github.com/Grazulex/laravel-draftable/wiki/Home)**
- **📚 [Getting Started Guide](https://github.com/Grazulex/laravel-draftable/wiki/Getting-Started)**
- **🔧 [Installation &amp; Configuration](https://github.com/Grazulex/laravel-draftable/wiki/Installation)**
- **🎯 [Core Concepts](https://github.com/Grazulex/laravel-draftable/wiki/Concepts)**
- **💡 [Examples &amp; Use Cases](https://github.com/Grazulex/laravel-draftable/wiki/Examples)**
- **🎨 [Artisan Commands](https://github.com/Grazulex/laravel-draftable/wiki/Commands)**
- **📋 [API Reference](https://github.com/Grazulex/laravel-draftable/wiki/API-Reference)**
- **📝 [Changelog](https://github.com/Grazulex/laravel-draftable/wiki/Changelog)**

🎨 Artisan Commands
------------------

[](#-artisan-commands)

Laravel Draftable includes powerful CLI commands for draft management:

```
# List all drafts with filtering options
php artisan draftable:list --model=Post --unpublished --limit=20

# Compare two specific versions of a model
php artisan draftable:diff Post 1 1 2 --format=json

# Clean up old drafts with safety checks
php artisan draftable:clear-old --days=30 --dry-run
```

🔍 Advanced Features
-------------------

[](#-advanced-features)

### Version Comparison

[](#version-comparison)

```
use Grazulex\LaravelDraftable\Services\DraftDiff;

$draftDiff = app(DraftDiff::class);
$differences = $draftDiff->compare($draft1, $draft2);

// Example output:
[
    'title' => [
        'type' => 'modified',
        'old' => 'Original Title',
        'new' => 'Updated Title'
    ],
    'content' => [
        'type' => 'added',
        'old' => null,
        'new' => 'New content here'
    ]
]
```

### Events Integration

[](#events-integration)

```
use Grazulex\LaravelDraftable\Events\{DraftCreated, DraftPublished, VersionRestored};

// Listen for draft events
Event::listen(DraftCreated::class, function ($event) {
    // Handle draft creation
});

Event::listen(DraftPublished::class, function ($event) {
    // Handle draft publication
});

Event::listen(VersionRestored::class, function ($event) {
    // Handle version restoration
});
```

### Database Migration

[](#database-migration)

The package includes an optimized migration:

```
Schema::create('drafts', function (Blueprint $table) {
    $table->id();
    $table->morphs('draftable');
    $table->json('payload');
    $table->unsignedBigInteger('version')->default(1);
    $table->foreignId('created_by')->nullable()->constrained('users');
    $table->timestamp('published_at')->nullable();
    $table->timestamps();

    // Performance indexes
    $table->index(['draftable_type', 'draftable_id']);
    $table->index('published_at');
    $table->index('version');
});
```

📊 Quality Metrics
-----------------

[](#-quality-metrics)

Laravel Draftable maintains exceptional quality standards:

- ✅ **128/128 tests passing** (100% success rate)
- ✅ **93.6% code coverage** (enterprise grade)
- ✅ **PHPStan level 5** (zero static analysis errors)
- ✅ **PSR-12 compliant** (Laravel Pint)
- ✅ **SOLID principles** (clean architecture)
- ✅ **Production ready** (zero known issues)

🎯 Use Cases
-----------

[](#-use-cases)

Perfect for:

- **Content Management Systems** - Blog posts, articles, pages
- **E-commerce Platforms** - Product descriptions, specifications
- **Documentation Sites** - Version-controlled documentation
- **Marketing Campaigns** - Draft and schedule content releases
- **User-Generated Content** - Moderation workflows with drafts
- **API Content** - Versioned API documentation and responses

🔮 Roadmap
---------

[](#-roadmap)

Future enhancements planned:

- 🔗 **Webhook Integration** - HTTP notifications on publish events
- 🎯 **Git-style Delta Storage** - Space-efficient version storage
- 🔄 **Approval Workflows** - Multi-step moderation processes
- 📱 **API Endpoints** - RESTful API for external integrations
- 🌍 **Multi-language Support** - Internationalization features

---

🤝 Contributing
--------------

[](#-contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

🔒 Security
----------

[](#-security)

If you discover any security-related issues, please email **** instead of using the issue tracker.

📝 Changelog
-----------

[](#-changelog)

Please see [RELEASES.md](RELEASES.md) for more information on what has changed recently.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

👥 Credits
---------

[](#-credits)

- **[Jean-Marc Strauven](https://github.com/Grazulex)**
- **[All Contributors](../../contributors)**

💬 Support
---------

[](#-support)

- 🐛 **[Report Issues](https://github.com/Grazulex/laravel-draftable/issues)**
- 💬 **[Discussions](https://github.com/Grazulex/laravel-draftable/discussions)**
- 📖 **[Documentation](https://github.com/Grazulex/laravel-draftable/wiki)**

---

 **Laravel Draftable** - Production-ready drafts and versioning
 for any Eloquent model with enterprise-grade quality. **Built with ❤️ following SOLID principles and clean code practices.**

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance57

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

276d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/888105bd54b6b7f7905523a16a1d08eebc2e5d39b19a4c174b5961bb4d52929b?d=identicon)[Grazulex](/maintainers/Grazulex)

---

Top Contributors

[![Grazulex](https://avatars.githubusercontent.com/u/4521546?v=4)](https://github.com/Grazulex "Grazulex (14 commits)")

---

Tags

laravelmodelpackagephppestlaravellaravel 11packageeloquentversioningclean codephp8draftsartisan-commandssolid-principlesdraftableproduction-readydiff-comparison

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/grazulex-laravel-draftable/health.svg)

```
[![Health](https://phpackages.com/badges/grazulex-laravel-draftable/health.svg)](https://phpackages.com/packages/grazulex-laravel-draftable)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[grazulex/laravel-devtoolbox

Swiss-army artisan CLI for Laravel — Scan, inspect, debug, and explore every aspect of your Laravel application from the command line.

1535.4k](/packages/grazulex-laravel-devtoolbox)[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2913.6k](/packages/shahghasiadil-laravel-api-versioning)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

1484.6k3](/packages/calebdw-larastan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
