owen-it / laravel-auditing

Record the change log from models in Laravel
https://laravel-auditing.com
MIT License
3.01k stars 387 forks source link

Record non modified fields #877

Closed nicktan147 closed 10 months ago

nicktan147 commented 10 months ago
Q A
Bug? no
New Feature? no
Framework Laravel
Framework version 10
Package version 13
PHP version 8.1

I would like to make it record all the fields regardless whether is it modified or not. However now it is only tracking fields that are modified only.

Screenshot 2023-11-27 154833

There are fields like name, country so forth, however due to its current functionality to keep track only what is changed, is there any option or configuration I can change to make it need not to track only fields that are being modified?

parallels999 commented 10 months ago

That would fill the DB with unnecessary data. 👎

nicktan147 commented 10 months ago

That would fill the DB with unnecessary data. 👎

I'm well aware of this, the reason is we need it to do a checksum against the old and the new values.

parallels999 commented 10 months ago

https://github.com/owen-it/laravel-auditing/blob/1a9cc9a442a048f3e41c2a424dc883b6df05103e/src/Auditable.php#L199-L215 You could override getUpdatedEventAttributes, It should go through all the attributes, instead of just the dirty ones

foreach ($this->attributes as $attribute => $value) {
    if ($this->isAttributeAuditable($attribute)) {
        $old[$attribute] = Arr::get($this->original, $attribute);
        $new[$attribute] = $value;
    }
}