Skip to content

Commit

Permalink
Merge pull request #5 from orisintel/feature/log-user-id
Browse files Browse the repository at this point in the history
Model user id fix/update
  • Loading branch information
Tom Schlick committed Aug 5, 2019
2 parents 3539e69 + 21cfe01 commit c92aed1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/model-auditlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@
'created_at',
'updated_at',
],

/*
* Function on the auth service provider that will return the user id editing a model
*/
'auth_id_function' => 'id',
];
5 changes: 5 additions & 0 deletions src/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static function recordChanges(int $event_type, $model) : void
$log->event_type = $event_type;
$log->subject_id = $model->getKey();
$log->occurred_at = now();

if (config('model-auditlog.enable_user_foreign_keys')) {
$log->user_id = \Auth::{config('model-auditlog.auth_id_function', 'id')}();
}

$log->setAttribute('field_name', $key);
$log->setAttribute('field_value_old', $model->getOriginal($key));
$log->setAttribute('field_value_new', $change);
Expand Down

0 comments on commit c92aed1

Please sign in to comment.