Skip to content

Commit 688786b

Browse files
author
Quentin Schmick
authored
Added precision as a config option for auditlog rcords (#4)
* Added precision as a config option for auditlog rcords * Added property to store fractional seconds
1 parent d1af31e commit 688786b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

config/model-auditlog.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@
5656
* Function on the auth service provider that will return the user id editing a model
5757
*/
5858
'auth_id_function' => 'id',
59+
60+
/*
61+
* Precision value used in generating audit log tables
62+
*/
63+
'log_timestamp_precision' => 0,
5964
];

src/Console/Commands/MakeModelAuditLogTable.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class MakeModelAuditLogTable extends Command
1515
*
1616
* @var string
1717
*/
18-
protected $signature = 'make:model-auditlog
18+
protected $signature = 'make:model-auditlog
1919
{existing-model-class : Define which model this auditlog should extend.}
2020
';
2121

@@ -125,6 +125,7 @@ public function createMigration($subject_model, array $config): void
125125
'{PROCESS_IDS_SETUP}' => $this->generateMigrationProcessStamps($config),
126126
'{FOREIGN_KEY_SUBJECT}' => $this->generateMigrationSubjectForeignKeys($subject_model, $config),
127127
'{FOREIGN_KEY_USER}' => $this->generateMigrationUserForeignKeys($config),
128+
'{PRECISION}' => $this->generatePrecisionValue($config),
128129
]);
129130

130131
$filename = $config['migration_path'] . DIRECTORY_SEPARATOR . $this->generateMigrationFilename($fileslug);
@@ -219,4 +220,9 @@ public function generateMigrationProcessStamps(array $config): string
219220

220221
return '';
221222
}
223+
224+
public function generatePrecisionValue(array $config): string
225+
{
226+
return (string) Arr::get($config, 'log_timestamp_precision', 0) ?? 0;
227+
}
222228
}

src/Models/BaseModel.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
*/
1616
abstract class BaseModel extends Model
1717
{
18+
public $dates = [
19+
self::CREATED_AT,
20+
self::CREATED_AT,
21+
'occurred_at',
22+
];
23+
24+
protected $dateFormat = 'Y-m-d H:i:s.u';
25+
1826
/**
1927
* Record the change in the appropriate audit log table.
2028
*

0 commit comments

Comments
 (0)