3

I'm using VentureCraft/revisionable for laravel-backpack-curd, I know it helps me to manage a model's change history, but I want to switch to a specific version of a model and get it completely as a model. is there any way to do this?

Let me explain more with an example: suppose we have a model called TODO I want to fetch different versions of it. Imagine I want to fetch something like this:

TODO::find(1)->revision(REVISION_NUMBER)->get();
Meysam Zarei
  • 419
  • 2
  • 14

1 Answers1

1

Are you using : https://github.com/laravel-backpack/revise-operation (that use VentureCraft/revisionable). Or the https://github.com/VentureCraft/revisionable with a backpack CRUD project ?

For what I know, the revisions are saved per field in a model that has the revisionable trait.

The trait VentureCraft/revisionable doesn't include a scope to narrow et get the value per, as you would like (->revision).

To achieve that, you should implement a function on your model to switch the model value to a revision id.

Like (roughly) :

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.
}

To implement this as a scope, it's different. Because each field change creates a new revision entry.

Maybe you would like to see which Todo as its origin values and its currents. That would be possible, since we can get each field that has a revision, and rewind back to the first oldValue.

Anyhow, hopes this help or narrow the solution for you.

M-A M
  • 21
  • 2