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(); + }); + } +};