debuqer/eloquent-memory 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

debuqer/eloquent-memory

Composer 安装命令:

composer require debuqer/eloquent-memory

包简介

Let the eloquent remember its current state of data

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Eloquent memory give you a Laravel model based time machine to perform time traveling through your models state.

$article = Article::create([
    'name' => 'Women, Life, Freedom',
    'content' => 'Hey this content just added,',
]);

// 5 minutes later

// let's change the content 
$article->update([
    'content' => 'Hey this content just changed,'
]);

// 
// Oops, we have changed our content by mistake, let's go back
$articleBeforeUpdate = $article->getStatyeOf(Carbon::now()->subMinutes(2)); 
$articleBeforeUpdate->save(); // will rollback the content of article to the 1 minute ago

Installation

You can install the package via composer:

composer require debuqer/eloquent-memory

You can publish and run the migrations with:

php artisan vendor:publish --tag="eloquent-memory-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="eloquent-memory-config"

This is the contents of the published config file:

return [
    'changes' => [
        'model-updated' => ModelUpdated::class,
        'model-created' => ModelCreated::class,
        'model-deleted' => ModelDeleted::class,
    ],
    'drivers' => [
        'default' => 'eloquent',

        'eloquent' => [
            'class_name' => \Debuqer\EloquentMemory\Repositories\Eloquent\EloquentTransitionPersistDriver::class,
            'connection' => 'default',
        ],
    ],
];

Usage

In order to force models to keep track of their states, CanRememberStates trait must be used in the model class

use Debuqer\EloquentMemory\CanRememberStates;

class Post extends Model 
{
    use CanRememberStates;
}

The model records their states in a database and the states can be retrieved by method getStateOf

$oldArticle = Article::find(5)->getStateOf(Carbon::now()->subMinutes(5));

Road map

  1. Fix migration, so the subject_key should be provide as an array

  2. Fix migration to be publishable via laravel

  3. no date_recorded field are stored

Testing

composer test

Changelog

This package is in dev mode and not recommend to use in production environment

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固