From 38223ad74c9357f3c904eff4d682e41d7482f33a Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Tue, 17 Mar 2026 12:46:32 +0800 Subject: [PATCH] add request log command --- .../app/Command/CleanRequestLogsCommand.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/app/Command/CleanRequestLogsCommand.php diff --git a/backend/app/Command/CleanRequestLogsCommand.php b/backend/app/Command/CleanRequestLogsCommand.php new file mode 100644 index 0000000..45065e3 --- /dev/null +++ b/backend/app/Command/CleanRequestLogsCommand.php @@ -0,0 +1,40 @@ +setDescription('清理过期的 API 请求日志'); + $this->addOption('days', 'd', InputOption::VALUE_OPTIONAL, '保留天数', 90); + } + + public function handle(): void + { + $days = (int) $this->input->getOption('days'); + $cutoff = Carbon::now()->subDays($days); + + $deleted = ApiRequestLog::query() + ->where('created_at', '<', $cutoff) + ->delete(); + + $this->info("已清理 {$deleted} 条超过 {$days} 天的请求日志。"); + } +}