setDescription('清理过期的 API 请求日志'); $this->addOption('days', 'd', InputOption::VALUE_OPTIONAL, '保留天数', 90); } public function handle(): void { $days = (int) $this->input->getOption('days'); if ($days < 1) { $this->error('保留天数必须大于 0'); return; } $cutoff = Carbon::now()->subDays($days); $deleted = ApiRequestLog::query() ->where('created_at', '<', $cutoff) ->delete(); $this->info("已清理 {$deleted} 条超过 {$days} 天的请求日志。"); } }