grazulex/laravel-snapshot

A powerful Laravel package for tracking, storing and comparing snapshots of your Eloquent models — cleanly and safely.

v1.0.0 2025-07-20 12:02 UTC

This package is auto-updated.

Last update: 2025-08-21 23:41:48 UTC


README

Laravel Snapshot

Advanced model versioning and snapshot system for Laravel applications

Latest Version Total Downloads License PHP Version Laravel Version Tests Code Style

Overview

Laravel Snapshot is a powerful package for tracking, storing and comparing snapshots of your Eloquent models — cleanly and safely. Perfect for audit trails, data recovery, debugging, and version control of your Laravel applications.

✨ Features

  • Manual & Automatic Snapshots - Capture model state on demand or automatically
  • 🔄 Model Restoration - Restore models to any previous snapshot state
  • 📊 Smart Comparisons - Deep diff analysis between snapshots
  • 💾 Multiple Storage Backends - Database, file system, or in-memory storage
  • 📈 Rich Analytics - Statistics, change frequency, and trend analysis
  • CLI Commands - Full command-line interface for all operations
  • 🧪 Testing Support - Built with Pest 3 and extensive test coverage
  • Production Ready - PHPStan level 5, optimized performance

� Quick Installation

# Install the package
composer require grazulex/laravel-snapshot

# Publish config (optional)
php artisan vendor:publish --tag=snapshot-config

# Run migrations
php artisan migrate

� Documentation

All documentation, examples, and guides are now available in our comprehensive Wiki:

📚 Visit the Laravel Snapshot Wiki →

Quick Navigation:

Topic Link
🏁 Getting Started Installation & Setup
📘 Basic Usage Creating & Managing Snapshots
⚙️ Configuration Configuration Options
🔄 Model Restoration Restoring Previous States
📊 Analytics & Reports Statistics & Analytics
CLI Commands Command Reference
💡 Examples Real-world Examples
🧪 Testing Testing Your Implementation
🔧 Advanced Usage Advanced Features
🚀 API Reference Complete API Documentation

💡 Quick Example

use Grazulex\LaravelSnapshot\Traits\HasSnapshots;

class Order extends Model
{
    use HasSnapshots;
}

// Create snapshots
$order = Order::find(1);
$order->snapshot('before-discount');

$order->update(['total' => 99.99]);
$order->snapshot('after-discount');

// Compare and restore
$diff = $order->compareWithSnapshot('before-discount');
$order->restoreFromSnapshot('before-discount');

// CLI usage
php artisan snapshot:save "App\Models\Order" --id=1 --label=backup
php artisan snapshot:restore "App\Models\Order" 1 backup
php artisan snapshot:diff before-discount after-discount

🎯 Use Cases

Perfect for:

  • Financial Systems - Transaction history and audit trails
  • Content Management - Version control for articles and pages
  • E-commerce - Product and order change tracking
  • Data Recovery - Point-in-time data restoration
  • Compliance - Regulatory audit trail requirements
  • Debugging - Track state changes during development

🔧 Requirements

  • PHP: ^8.3
  • Laravel: ^12.19
  • Carbon: ^3.10

🧪 Quality Assurance

  • 95 Tests passing with Pest 3
  • PHPStan Level 5 compliance
  • 60%+ Code Coverage
  • Laravel Pint code style
  • Comprehensive CLI testing

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Commands

composer run-script full    # Run all quality checks
composer run-script test    # Run tests
composer run-script pint    # Fix code style
composer run-script phpstan # Static analysis

🔒 Security

If you discover a security vulnerability, please review our Security Policy.

📄 License

Laravel Snapshot is open-sourced software licensed under the MIT license.

📚 Complete Documentation | 💬 Discussions | � Issues

Made with ❤️ for the Laravel community