subDays(7); $files = File::where('is_temp', true) ->where('created_at', '<', $threshold) ->get(); $count = $files->count(); $this->info("Found {$count} temp files to delete"); $deleted = 0; foreach ($files as $file) { try { // Delete physical file if (Storage::disk('tenant')->exists($file->file_path)) { Storage::disk('tenant')->delete($file->file_path); } // Force delete from DB $file->forceDelete(); $deleted++; } catch (\Exception $e) { $this->error("Failed to delete file ID {$file->id}: {$e->getMessage()}"); } } $this->info("Cleanup completed: {$deleted}/{$count} files deleted"); return Command::SUCCESS; } }