Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Revisionable Laravel Package

sofa/revisionable

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:
    • Lightweight & Modular: Fits seamlessly into Laravel’s Eloquent ORM without requiring major architectural changes. Leverages Laravel’s existing service provider and config systems, minimizing intrusion.
    • Bulk Revision Handling: Stores all changed fields in a single revision entry, simplifying version comparison and diff operations. Ideal for audit logs, time-tracked data, or collaborative editing systems (e.g., CMS, wikis, or multi-user dashboards).
    • Event-Driven: Integrates with Laravel’s event system (e.g., revisionable.saved, revisionable.deleted), enabling hooks for custom logic (e.g., triggering notifications, syncing with external systems).
    • Soft Deletes Compatibility: Supports Laravel’s soft deletes out of the box, preserving revision history even for "deleted" records.
  • Cons:
    • No Native Laravel 8/9+ Support: Last release in 2023 targets Laravel 5.x, requiring customization for newer Laravel versions (e.g., package discovery, namespace changes).
    • Limited Query Flexibility: Revisions are stored in a single table (revisions), which may not scale for complex queries (e.g., filtering by specific field changes). Requires raw SQL or custom scopes for advanced use cases.
    • No Built-in UI: Lacks pre-built admin interfaces or APIs for revision management (e.g., rollback, diff views), necessitating frontend development.

Integration Feasibility

  • Eloquent Models: Works with any Eloquent model by applying the Revisionable trait. Minimal boilerplate—just add use Sofa\Revisionable\RevisionableTrait and configure the revisionable() method.
  • Database Schema: Adds a revisions table with foreign keys to the original model. Migration is handled via the package’s publisher or manual SQL.
  • Authentication: Supports Laravel’s default guard, JWT, or Sentry/Sentinel. Extensible for custom auth systems via the revisionable() method’s guard parameter.
  • Performance: Bulk inserts for revisions may impact write performance during high-traffic events. Read operations (e.g., fetching revisions) are optimized but could benefit from indexing (e.g., created_at, user_id).

Technical Risk

  • Laravel Version Mismatch: High risk for projects using Laravel 8/9/10 due to deprecated features (e.g., config/app.php vs. config/services.php, namespace changes). Mitigation: Fork or patch the package, or use a compatible alternative like spatie/laravel-activitylog.
  • Data Bloat: Revisions table grows linearly with model updates. Risk of storage bloat for high-frequency updates (e.g., real-time systems). Mitigation: Implement TTL policies or archival strategies.
  • Concurrency Issues: No built-in locking for revision creation, risking race conditions in multi-user environments. Mitigation: Use Laravel’s database transactions or optimistic locking.
  • Testing Overhead: Requires thorough testing of revision-related logic (e.g., edge cases like partial updates, soft deletes). Mocking the Revisionable trait may be necessary for unit tests.

Key Questions

  1. Laravel Version Compatibility:
    • Is the project locked to Laravel 5.x, or can we adapt the package for Laravel 8/9+?
    • If upgrading, what are the migration costs (e.g., namespace changes, config paths)?
  2. Revision Use Cases:
    • Are revisions needed for all models, or only specific ones (e.g., critical data like user profiles)?
    • What’s the expected revision volume (e.g., 10k/month vs. 1M/month)? Does this require archival or pruning?
  3. Query Patterns:
    • Will the team need to query revisions by specific fields (e.g., "show me all changes to price")? If so, custom scopes or views may be needed.
    • Are there performance requirements for fetching revision histories (e.g., paginated APIs)?
  4. UI/UX Requirements:
    • Is a built-in revision UI (e.g., diff tool, rollback button) needed, or will this be handled separately?
  5. Alternatives:
    • Have we evaluated alternatives like spatie/laravel-activitylog or laravel-auditing for broader feature sets (e.g., nested models, event hooks)?
  6. Compliance:
    • Are revisions required for regulatory/audit purposes? If so, does the package meet retention/immutability needs?

Integration Approach

Stack Fit

  • Laravel Core: Fully compatible with Eloquent, events, and Laravel’s service container. Leverages existing Laravel patterns (e.g., traits, service providers).
  • PHP Version: Supports PHP 5.4+, but PHP 7.4+ is recommended for performance. No major conflicts with modern PHP.
  • Database: Works with MySQL, PostgreSQL, SQLite, and SQL Server. Assumes standard Laravel migrations.
  • Authentication: Integrates with Laravel’s default auth, JWT (via tymon/jwt-auth), or Sentry/Sentinel. Custom auth systems require extending the revisionable() method.
  • Testing: Compatible with Laravel’s testing tools (e.g., phpunit, pest). May need custom assertions for revision-related logic.

Migration Path

  1. Assessment Phase:
    • Audit existing models to identify candidates for revision tracking.
    • Review current database schema and backup the revisions table migration.
  2. Package Installation:
    composer require sofa/revisionable
    
    • For Laravel 8/9/10: Fork the package or patch it to resolve version-specific issues (e.g., namespace changes).
  3. Configuration:
    • Publish the config file:
      php artisan vendor:publish --provider="Sofa\Revisionable\Laravel\ServiceProvider"
      
    • Update config/sofa_revisionable.php for customizations (e.g., revision_table_name, guard).
  4. Model Integration:
    • Add the trait to target models:
      use Sofa\Revisionable\RevisionableTrait;
      
      class Post extends Model {
          use RevisionableTrait;
      
          public function revisionable()
          {
              return true; // or customize guard/table
          }
      }
      
    • Run migrations to create the revisions table.
  5. Testing:
    • Write unit tests for models using the trait, focusing on:
      • Revision creation on create()/update().
      • Soft delete behavior.
      • Custom guards/auth.
    • Test edge cases (e.g., mass updates, concurrent writes).
  6. Deployment:
    • Roll out in stages (e.g., non-critical models first).
    • Monitor database growth and query performance.

Compatibility

  • Laravel 5.x: Out-of-the-box compatibility.
  • Laravel 8/9/10: Requires patches for:
    • Service provider registration (use PackageServiceProvider).
    • Config file location (config/sofa_revisionable.php vs. config/revisionable.php).
    • Namespace adjustments (e.g., Illuminate\Support\Facades\Config).
  • Third-Party Packages:
    • Conflicts unlikely, but test with packages that modify Eloquent events (e.g., laravel-debugbar).
    • May need to reorder event listeners if revisions and other packages hook into the same events.
  • Custom Fields:
    • Non-serializable fields (e.g., relationships, JSON columns) may require custom serialization in the revisionable() method.

Sequencing

  1. Phase 1: Core Integration
    • Implement revisions for 1–2 critical models (e.g., User, Product).
    • Validate revision creation, retrieval, and diff logic.
  2. Phase 2: UI/API Layer
    • Build endpoints or admin panels for viewing revisions (e.g., /posts/{id}/revisions).
    • Implement rollback or restore functionality if needed.
  3. Phase 3: Optimization
    • Add indexes to the revisions table (e.g., model_id, created_at).
    • Implement archival/pruning for old revisions (e.g., keep last 12 months).
  4. Phase 4: Monitoring
    • Set up alerts for abnormal revision volume or failed revision creation.
    • Log revision-related errors centrally (e.g., Sentry).

Operational Impact

Maintenance

  • Package Updates:
    • No active maintenance since 2023. Forking or patching may be necessary for long-term use.
    • Monitor for security vulnerabilities (e.g., SQL injection in custom queries).
  • Customizations:
    • Extensions (e.g., custom guards, field serialization) require documentation and version control.
    • Overrides to the revisionable() method should be tested during deployments.
  • Deprecation Risk:
    • If Laravel 5.x is deprecated, the package may become unsustainable. Plan for migration to a maintained alternative (e.g., spatie/laravel-activitylog).

Support

  • Troubleshooting:
    • Common issues: missing revisions, auth guard misconfig
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui