request = $request; $this->invoice = $invoice; } public function run() { //the request may have buried in it additional actions we should automatically perform on the invoice if($this->request->has('send_email')) { } if($this->request->has('auto_bill')) { } if($this->request->has('paid')) { } return $this->invoice; } private function sendEmail() { $reminder_template = $this->invoice->calculateTemplate(); $this->invoice->invitations->load('contact.client.country','invoice.client.country','invoice.company')->each(function ($invitation) use($reminder_template){ $email_builder = (new InvoiceEmail())->build($invitation, $reminder_template); EmailInvoice::dispatch($email_builder, $invitation, $this->invoice->company); }); if ($this->invoice->invitations->count() > 0) { event(new InvoiceWasEmailed($this->invoice->invitations->first(), $this->invoice->company)); } } }