processEmails(); } else { //multiDB environment, need to foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); $this->processEmails(); } } } private function processEmails() { $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) { EmailEntity::dispatch($invitation, $invitation->company); } } }); } }