Skip to content

Commit 21cfe01

Browse files
committed
Added a config option to change the auth id function and updated base model to use it
1 parent 3539e69 commit 21cfe01

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

config/model-auditlog.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@
5151
'created_at',
5252
'updated_at',
5353
],
54+
55+
/*
56+
* Function on the auth service provider that will return the user id editing a model
57+
*/
58+
'auth_id_function' => 'id',
5459
];

src/Models/BaseModel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public static function recordChanges(int $event_type, $model) : void
4141
$log->event_type = $event_type;
4242
$log->subject_id = $model->getKey();
4343
$log->occurred_at = now();
44+
45+
if (config('model-auditlog.enable_user_foreign_keys')) {
46+
$log->user_id = \Auth::{config('model-auditlog.auth_id_function', 'id')}();
47+
}
48+
4449
$log->setAttribute('field_name', $key);
4550
$log->setAttribute('field_value_old', $model->getOriginal($key));
4651
$log->setAttribute('field_value_new', $change);

0 commit comments

Comments
 (0)