我正在为 laravel-backpack-curd 使用 VentureCraft/revisionable,我知道它可以帮助我管理模型的更改历史,但我想切换到模型的特定版本并将其完全作为模型。有什么办法吗?
让我用一个例子来解释一下:假设我们有一个名为 TODO 的模型,我想获取它的不同版本。想象一下,我想获取这样的东西:
TODO::find(1)->revision(REVISION_NUMBER)->get();
我正在为 laravel-backpack-curd 使用 VentureCraft/revisionable,我知道它可以帮助我管理模型的更改历史,但我想切换到模型的特定版本并将其完全作为模型。有什么办法吗?
让我用一个例子来解释一下:假设我们有一个名为 TODO 的模型,我想获取它的不同版本。想象一下,我想获取这样的东西:
TODO::find(1)->revision(REVISION_NUMBER)->get();
您在使用:https ://github.com/laravel-backpack/revise-operation (使用 VentureCraft/revisionable)。或者带有背包 CRUD 项目的https://github.com/VentureCraft/revisionable ?
据我所知,修订是按具有可修订特征的模型中的字段保存的。
该特征 VentureCraft/revisionable
不包括缩小范围和获取每个值的范围,如您所愿(->revision
)。
为此,您应该在模型上实现一个函数以将模型值切换为修订 ID。
喜欢(大致):
public function previewAsRevision($revision_id) {
// 1. Get the current model's field values.
// 2. Get the target revision by $id to get the field modified and both old and new value.
// 3. temporary change the $this->$field_name value to the revision value.
// 4. return the temporary Model object with the modified value.
//kindish and depends on what are the operations needed to be done with this.
}
要将其实现为scope
,它是不同的。因为每个字段更改都会创建一个新的修订条目。
也许你想看看哪个 Todo 作为它的原始值和它的电流。这是可能的,因为我们可以获取每个有修订的字段,然后倒回到第一个oldValue
.
无论如何,希望这对您有所帮助或缩小解决方案。