Skip to content

Grazulex/laravel-snapshot

Laravel Snapshot

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:

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

About

πŸ“Έ Track, store and compare snapshots of your Eloquent models β€” cleanly and safely.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Languages