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

Create revisions on updating a model #288

Open
divdax opened this issue Jun 30, 2017 · 5 comments
Open

Create revisions on updating a model #288

divdax opened this issue Jun 30, 2017 · 5 comments

Comments

@divdax
Copy link

divdax commented Jun 30, 2017

Hey,

i think when a models is updated via the update() method a revision should be created for every item when i run e.g.

Track::whereActive(1)->update(['supplier' => $new_id]);

currently only a revision i created when i save one model.

@robindirksen1
Copy link

Any progress with this issue?

@DanDvoracek
Copy link

Hitting the same issue. Any thoughts ?

@jayzyaj
Copy link

jayzyaj commented Jul 12, 2018

Same with me on 5.5

@jpark00
Copy link

jpark00 commented Jul 13, 2018

The package actually doesn't catch the Eloquent update events, so it doesn't know to create a revision during an update. You might be able to get around this by "overriding" the trait and including the events:

class YourModel extends Model {
    use RevisionableTrait {
        bootRevisionableTrait as protected unused;
    }

    .....

    //Override trait function
    public static function bootRevisionableTrait() {
        static::saving(function ($model) {
            $model->preSave();
        });
        static::saved(function ($model) {
            $model->postSave();
        });
        static::created(function($model){
            $model->postCreate();
        });
        static::deleted(function ($model) {
            $model->preSave();
            $model->postDelete();
        });

        //Add in the update events
        static::updating(function ($model) {
            $model->preSave();
        });
        static::updated(function ($model) {
            $model->postSave();
        });

    }
}

@venux92
Copy link

venux92 commented Dec 5, 2018

Any news on this issue? I have the same issue on Laravel 5.7

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

No branches or pull requests

6 participants