Skip to content

Commit a5ac38f

Browse files
authored
Merge pull request #8 from dipesh79/hidden
refactor: Exclude hidden attributes from log data
2 parents 8f94ffc + d621f3c commit a5ac38f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/Traits/HasLog.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ public static function boot()
4242
*/
4343
static::updated(function ($model) {
4444
if (auth()->check()) {
45+
$excluded = $model->hidden ?? [];
46+
47+
$old = collect($model->getRawOriginal())->except($excluded)->toArray();
48+
$changes = collect($model->getChanges())->except($excluded)->toArray();
49+
4550
$model->logs()->create([
4651
'action' => 'Update',
4752
'ip_address' => request()->ip(),
4853
'device' => request()->userAgent(),
4954
'user_id' => auth()->user()->id,
50-
'old_data' => json_encode($model->getRawOriginal()),
51-
'changed_values' => json_encode($model->getChanges())
55+
'old_data' => json_encode($old),
56+
'changed_values' => json_encode($changes),
5257
]);
5358
}
5459
});

0 commit comments

Comments
 (0)