processEmails(); } else { //multiDB environment, need to foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); $this->processEmails(); } } } private function processEmails() { \Log::error("processing emails"); //info("process emails"); //@todo check that the quota is available for the job $email_jobs = SystemLog::where('event_id', SystemLog::EVENT_MAIL_RETRY_QUEUE)->get(); $email_jobs->each(function($job){ $job_meta_array = $job->log; $invitation = $job_meta_array['entity_name']::where('key', $job_meta_array['invitation_key'])->with('contact')->first(); if($invitation->invoice){ $email_builder = (new InvoiceEmail())->build($invitation, $job_meta_array['reminder_template']); if ($invitation->contact->send_email && $invitation->contact->email) { EmailInvoice::dispatch($email_builder, $invitation, $invitation->company); } } }); } }