nocturnalsm/pendingupdate

dev-master 2021-03-04 09:05 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:08 UTC


README

此包可以在模型更新时关联其原始数据,而更新的字段将存储到更新模型中。之后,您可以应用更新或取消更新

安装后,您可以进行如下操作

$model = Model::where("name", "Sugiarto");
$model->name = 'Bambang';
$model->pendingUpdate(); // put this after you've made the changes
$model->save();
echo $model->name;
// this won't print 'Bambang', but will still print 'Sugiarto'
// but if you do
$model->usePending();
echo $model->name;
// it will print Bambang;

// then if you want to apply the updated model to the original, you use
$model->applyUpdate();
// or to cancel:
$model->cancelUpdate();

安装

  1. 您可以使用composer安装此包。在您的Laravel项目文件夹中,输入
composer require nocturnalsm/pendingupdate
  1. 可选:服务提供程序将自动注册。或者,您也可以手动将服务提供程序添加到您的 config/app.php 文件中。
'providers' => [
    // ...
    NocturnalSm\PendingUpdate\PendingUpdateServiceProvider::class,
];
  1. 发布迁移文件
php artisan vendor:publish --provider="NocturnalSm\PendingUpdate\PendingUpdateServiceProvider" --tag=migrations
  1. 并运行迁移
php artisan migrate
  1. 将PendingUpdate特性添加到您的模型中
use NocturnalSm\PendingUpdate\PendingUpdate;

class Model extends Model
{
    use PendingUpdate;
}

函数

// pending the update
$model->pendingUpdate();

// apply update to the data
$model->applyUpdate();

// cancel the update and return the data to the original 
$model->cancelUpdate();

// return pending updates for the model
$model->updates();

// check if the pending data with the specified $key column has change
$model->hasPendingValue($key);

// get the pending value for a column specified with $key
$model->getPendingValue($key);

// make subsequent call to the data values to return the pending value
$model->usePending(); 

// make subsequent call to the data values to return the original value
$model->useOriginal();

需要UI吗?

此包不附带任何UI,您需要自己构建。但如果有需要实现它,可以联系我。

联系 & 支持

我是一名来自印度尼西亚的网页开发者。我提供网页开发服务,特别是使用Laravel。请通过电子邮件联系我 basugi99@gmail.com

许可

MIT许可(MIT)。请参阅 许可文件 了解更多信息。