/** * Importer class. * * @return \Symfony\Component\HttpFoundation\Response */ public function import() { $index = 0; $batch = []; foreach ($this->medicalCenterRepository->all() as $index => $medCenter) { $email = $medCenter->email; if ($email === '') { continue; } $batch[] = ['email' => compact('email'), 'merge_vars' => ['TOKEN' => $medCenter->token, 'NAME' => $medCenter->name, 'COUNTRY' => $medCenter->country, 'EMAIL' => $medCenter->email]]; } // Subscribe to Newsletter $results = $this->newsletter->batchSubscribeTo('TheseEcho', $batch, false, true); // Errors if ($results['error_count']) { return $this->response->make('There are errors ' . print_r($results['errors']) . '.', 405); } // Success return $this->response->make("Subscribed {$index} centers.", 200); }