Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$revisionCreationsEnabled only tracks created_at #267

Open
eleftrik opened this issue Jan 4, 2017 · 7 comments
Open

$revisionCreationsEnabled only tracks created_at #267

eleftrik opened this issue Jan 4, 2017 · 7 comments

Comments

@eleftrik
Copy link

eleftrik commented Jan 4, 2017

Hi, I just installed revisionable in a Laravel 5.3 project.

In my models I set $revisionCreationsEnabled = true. When I create a record (through Eloquent), only key created_at gets stored in the revisions table.
Shouldn't it save any model property?
If my model has 3 properties, let's say $name, $description, $state, when I create a record I'm expecting to see 3 rows (3 keys) in the revisions table, one for each model property. Am I wrong?

Thank you.

@Pes8
Copy link

Pes8 commented Jan 4, 2017

Same issue here using laravel 5.2 & revisionable 1.28.

@stierler
Copy link
Collaborator

stierler commented Jan 7, 2017

This could be an enhancement/additional option, but that is the expected behavior.

When I've used it/tracked revisions in the past, I can assume that that the "created_at" indicates when it was created, and then any revision after that is a modification. My revert functionality will take the current record and traverse backward down the revisions to get to the "original".

I agree that that is extra work (and also has the caveat if you don't record certain columns).

@neoacevedo
Copy link

I have created -and closed- this issue because I didn't see this other.

If is needed to record all fields it could be done overriding boot method and using the static saving or saved method to create a new record in revisions table.

@Cyrille37
Copy link

This issue can be closed, isn't it ?

@fico7489
Copy link

same here

@Prophe1
Copy link

Prophe1 commented Jul 25, 2020

still exists

@coamw2
Copy link

coamw2 commented Mar 7, 2023

I have implemented the below on the model's boot method to store the starting values for fields I need

      public static function boot()
      {
          parent::boot();
  
          self::created(function($model){
              $revisions = [];
              $revisions[] = array(
                  'revisionable_type' => $model->getMorphClass(),
                  'revisionable_id' => $model->getKey(),
                  'key' => 'my_field',
                  'old_value' => null,
                  'new_value' => $model->my_field,
                  'user_id' => Auth::check() ? Auth::user()->getAuthIdentifier() : null,
                  'created_at' => new DateTime(),
                  'updated_at' => new DateTime(),
              );
              $revision = Revisionable::newModel();
              DB::table($revision->getTable())->insert($revisions);
          });
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants