From 447e889a4fa9b1665ec0bc32c7cc06e36270ca24 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Wed, 10 Jul 2024 08:36:24 +0200 Subject: [PATCH] Fix default timestamp for activity logs (#468) * fix default timestamp for activity logs * fix phpstan --- app/Models/ActivityLog.php | 4 +++ ...948_fix-activity-log-timestamp-default.php | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 database/migrations/2024_07_08_112948_fix-activity-log-timestamp-default.php diff --git a/app/Models/ActivityLog.php b/app/Models/ActivityLog.php index 06fd2d108..bb6149c14 100644 --- a/app/Models/ActivityLog.php +++ b/app/Models/ActivityLog.php @@ -140,6 +140,10 @@ class ActivityLog extends Model { parent::boot(); + static::creating(function (self $model) { + $model->timestamp = Carbon::now(); + }); + static::created(function (self $model) { Event::dispatch(new ActivityLogged($model)); }); diff --git a/database/migrations/2024_07_08_112948_fix-activity-log-timestamp-default.php b/database/migrations/2024_07_08_112948_fix-activity-log-timestamp-default.php new file mode 100644 index 000000000..892ca1826 --- /dev/null +++ b/database/migrations/2024_07_08_112948_fix-activity-log-timestamp-default.php @@ -0,0 +1,28 @@ +timestamp('timestamp')->default(null)->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('activity_logs', function (Blueprint $table) { + $table->timestamp('timestamp')->useCurrent()->change(); + }); + } +};