upload; $event = $upload->event; $user = $event->user; $upload->update(['status' => 'uploading', 'upload_started_at' => now()]); try { if (! $event->google_drive_folder_id) { throw new \RuntimeException('Event has no Google Drive folder configured.'); } if (! file_exists($this->tempFilePath)) { throw new \RuntimeException('Temporary file not found.'); } $result = $googleDrive->uploadFile( $user, $this->tempFilePath, $event->google_drive_folder_id, $upload->original_filename, $upload->mime_type ); $upload->update([ 'google_drive_file_id' => $result['id'], 'google_drive_web_link' => $result['webViewLink'] ?? null, 'status' => 'completed', 'upload_completed_at' => now(), 'error_message' => null, ]); } catch (\Throwable $e) { $upload->update([ 'status' => 'failed', 'error_message' => $e->getMessage(), 'upload_completed_at' => now(), ]); throw $e; } finally { if (file_exists($this->tempFilePath)) { @unlink($this->tempFilePath); } } } }