HasSnapshot trait is non-intrusive; it can be added to existing models without modifying core logic.vendor:publish commands automate this.serialize() depth limits or database field size limits (e.g., MySQL TEXT/JSON constraints).snapshotable_id, created_at).snapshot:model:id).php artisan vendor:publish --tag="snapshot-migrations"
php artisan vendor:publish --tag="snapshot-config"
softDeletes if needed).HasSnapshot to target models:
use Oobook\Snapshot\Concerns\HasSnapshot;
class Product extends Model {
use HasSnapshot;
}
config/snapshot.php:
'snapshotable' => [
'fields' => ['name', 'price', 'description'],
'relationships' => ['category', 'images'],
],
class Product extends Model {
use HasSnapshot;
protected static function booted() {
static::updating(function ($model) {
// Pre-snapshot validation
});
static::saved(function ($model) {
// Post-snapshot actions (e.g., log, notify)
});
}
}
select() to limit fields).composer.json if stability is critical.snapshotable_id, created_at.gzip or Laravel’s file storage for large snapshots.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Serialization errors | Corrupted snapshots | Validate data before snapshot; use try-catch blocks. |
| Database outages | Lost snapshots | Enable database replication and backups. |
| Uncontrolled snapshot growth | Storage exhaustion | Set size limits or TTL policies. |
| Relationship circular references | Infinite loops | Exclude circular relationships from snapshots or use ignoredRelationships. |
| Schema drift | Incompatible snapshots | Version snapshot data (e.g., schema_version column). |
| Queue failures (async snapshots) | Delayed/failed snapshots | Implement **dead- |
How can I help you explore Laravel packages today?