spatie / activitylog

A very simple activity logger to monitor the users of your website or application
https://spatie.be/opensource/laravel
MIT License
582 stars 75 forks source link

Logging Old and New Values on Update #21

Closed codydh closed 8 years ago

codydh commented 8 years ago

I'm trying to implement logging on a model of mine. Namely, when a value is updated, I'd like to log what the previous value was, and what the new value is. Is there a straightforward way to do this using ActivityLog?

sebastiandedeyne commented 8 years ago

You'd have to manually bind an event to updating. Quick example:

protected static function boot()
{
    static::updating(function ($model) {
        Activity::log("{$model->name} just updated to {$model->getOriginal('name')}");
    }
}