承接 braankoo/eloquent-snapshot 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

braankoo/eloquent-snapshot

最新稳定版本:v1.0.1

Composer 安装命令:

composer require braankoo/eloquent-snapshot

包简介

Laravel Eloquent Snapshot is a lightweight package that enables automatic or manual snapshots of Eloquent model states. Ideal for audit trails, change tracking, or rollback functionality, this package stores historical records of model data in a flexible and efficient way.

README 文档

README

Eloquent Snapshot is a Laravel package that provides functionality for storing and restoring snapshots of Eloquent models. This is useful for tracking changes, creating backups, or implementing undo functionality in your application.

Installation

Install the package via Composer:

composer require braankoo/eloquent-snapshot

Usage

Storing Snapshots

Use the EloquentSnapshotStoreService to store snapshots of Eloquent models:

use Braankoo\EloquentSnapshot\EloquentSnapshotFacade as Snapshot;

Snapshot::create($model);
Snapshot::create([$model1, $model2]);
Snapshot::create(collect([$model1, $model2]));

Restoring Snapshots

Use the EloquentSnapshotRestoreService to restore snapshots of Eloquent models:

use Braankoo\EloquentSnapshot\EloquentSnapshotFacade as Snapshot;
use Braankoo\EloquentSnapshot\EloquentSnapshotFilter;
Snapshot::restore(Model::first()); // Restore the last model snapshot
Snapshot::restore(Model::first(), (new EloquentSnapshotFilter())->first());
Snapshot::restore(Model::first(), (new EloquentSnapshotFilter())->latest());

Filtering Snapshots

You can filter snapshots using the EloquentSnapshotFilter class:

use Braankoo\EloquentSnapshot\EloquentSnapshotFilter;
use Braankoo\EloquentSnapshot\EloquentSnapshotFacade as Snapshot;
Snapshot::restore(Model::first(), (new EloquentSnapshotFilter())->before(Carbon::now()->subDays(7))->after(Carbon::now()->subDays(30))->first());

Features

  • Store snapshots of Eloquent models, arrays, or collections.
  • Restore snapshots with optional filtering.
  • Transactional operations for data integrity.
  • Supports chunked inserts for large datasets.

Configuration

No additional configuration is required. The package uses Laravel's default database connection. All you have to do is run the migrations to create the necessary tables:

php artisan migrate

Contributing

Contributions are welcome! Please submit a pull request or open an issue for any bugs or feature requests.

License

This package is open-source and licensed under the MIT License.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-14