invoice = $invoice; $this->reminder_template = $reminder_template; $this->contact = $contact; } /** * Builds the correct template to send * @param string $reminder_template The template name ie reminder1 * @return array */ public function run() { if (!$this->reminder_template) { $this->reminder_template = $this->invoice->calculateTemplate(); } $this->invoice->invitations->each(function ($invitation) { $email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template); if ($invitation->contact->send_email && $invitation->contact->email) { EmailInvoice::dispatch($email_builder, $invitation, $invitation->company); } }); } }