importId, ['status' => 'processing'], now()->addDay()); try { $stats = $this->runSync($this->filePath); ImportLog::create([ 'type' => $this->getImportType(), 'user_id' => $this->userId, 'total' => $stats['total'] ?? 0, 'created' => $stats['created'] ?? 0, 'updated' => $stats['updated'] ?? 0, 'inactivated' => $stats['inactivated'] ?? 0, 'imported_at' => now(), ]); Cache::put($this->importId, [ 'status' => 'completed', 'stats' => $stats, ], now()->addDay()); } finally { $this->cleanupFile(); } } public function failed(Throwable $e): void { Cache::put($this->importId, [ 'status' => 'failed', 'message' => $e->getMessage(), ], now()->addDay()); $this->cleanupFile(); } abstract protected function runSync(string $filePath): array; abstract protected function getImportType(): string; private function cleanupFile(): void { Storage::delete($this->filePath); } }