【问题标题】:Is there any way to get a specific version of a model in laravel backpack-crud?有没有办法在 laravel 背包-crud 中获得特定版本的模型?
【发布时间】:2020-08-25 20:46:42
【问题描述】:

我正在为 laravel-backpack-curd 使用 VentureCraft/revisionable,我知道它可以帮助我管理模型的更改历史,但我想切换到模型的特定版本并将其完全作为模型。有没有办法做到这一点?

让我用一个例子来解释一下: 假设我们有一个名为 TODO 的模型,我想获取它的不同版本。想象一下我想获取这样的东西:

TODO::find(1)->revision(REVISION_NUMBER)->get();

【问题讨论】:

  • 愿意分享一些代码(就像您现在拥有的与您期望的那样)?
  • @Tpojka 我已经添加了更多解释。

标签: laravel laravel-backpack revisionable


【解决方案1】:

您是否在使用:https://github.com/laravel-backpack/revise-operation(使用 VentureCraft/revisionable)。还是带有背包 CRUD 项目的 https://github.com/VentureCraft/revisionable

据我所知,修订是按字段保存在具有可修订特征的模型中的。

traitVentureCraft/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

无论如何,希望这对您有所帮助或缩小解决方案的范围。

【讨论】:

    猜你喜欢
    • 2019-07-23
    • 2019-09-27
    • 1970-01-01
    • 2017-03-22
    • 2020-07-15
    • 1970-01-01
    • 2013-12-21
    • 2017-12-14
    • 1970-01-01
    相关资源
    最近更新 更多