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.
- οΏ½ 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
# Install the package
composer require grazulex/laravel-snapshot
# Publish config (optional)
php artisan vendor:publish --tag=snapshot-config
# Run migrations
php artisan migrate
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 |
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
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
- PHP: ^8.3
- Laravel: ^12.19
- Carbon: ^3.10
- β 95 Tests passing with Pest 3
- β PHPStan Level 5 compliance
- β 60%+ Code Coverage
- β Laravel Pint code style
- β Comprehensive CLI testing
We welcome contributions! Please see our Contributing Guide for details.
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
If you discover a security vulnerability, please review our Security Policy.
Laravel Snapshot is open-sourced software licensed under the MIT license.
π Complete Documentation | π¬ Discussions | οΏ½ Issues
Made with β€οΈ for the Laravel community