parallelteam/laravel-drafts 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

parallelteam/laravel-drafts

Composer 安装命令:

composer require parallelteam/laravel-drafts

包简介

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

README 文档

README

Laravel Draftable

Production-ready drafts, versioning, and publication flow for any Eloquent model

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

Latest Version Total Downloads License PHP Version Laravel Version Tests Coverage Code Style Static Analysis

🚀 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

  • 📝 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

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

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

  • PHP 8.2+
  • Laravel 11.0+

� Complete Documentation

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

📖 👉 Laravel Draftable Wiki

The wiki includes:

🎨 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

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

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

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

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

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

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

Please see CONTRIBUTING.md for details.

🔒 Security

If you discover any security-related issues, please email jms@grazulex.be instead of using the issue tracker.

📝 Changelog

Please see RELEASES.md for more information on what has changed recently.

📄 License

The MIT License (MIT). Please see License File for more information.

👥 Credits

💬 Support

Laravel Draftable - Production-ready drafts and versioning
for any Eloquent model with enterprise-grade quality.

Built with ❤️ following SOLID principles and clean code practices.

parallelteam/laravel-drafts 适用场景与选型建议

parallelteam/laravel-drafts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「package」 「versioning」 「laravel」 「eloquent」 「draftable」 「drafts」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 parallelteam/laravel-drafts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 parallelteam/laravel-drafts 我们能提供哪些服务?
定制开发 / 二次开发

基于 parallelteam/laravel-drafts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 49
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-09