data = $data; $this->template = Template::find($template); $this->invoicePdf = $invoicePdf; $this->invoicePdfFileName = $invoicePdfFileName; } public function envelope() { if (!$this->template) { throw new \RuntimeException('Email template ID=2 (CreateVirtualMachine) not found in database.'); } return new Envelope( subject: str_replace("{\$os_name}", $this->data['os_name'] ?? '', $this->template->subject), ); } public function content() { if (!$this->template) { throw new \RuntimeException('Email template ID=2 (CreateVirtualMachine) not found in database.'); } return new Content( view: 'emails.template', with: [ 'template' => str_replace( [ "{\$company_name}", "{\$company_logo}", "{\$client_name}", "{\$product_name}", "{\$product_billing}", "{\$product_price}", "{\$service_host}", "{\$service_username}", "{\$service_port}", "{\$service_password}", "{\$os_name}", "{\$service_due_exp}" ], [ $this->data['company_name'], $this->data['company_logo'], $this->data['client_name'], $this->data['product_name'], $this->data['product_billing'], $this->data['product_price'], $this->data['service_host'], $this->data['service_username'], $this->data['service_port'], $this->data['service_password'], $this->data['os_name'], $this->data['service_due_exp'], ], $this->template->message) ] ); } public function attachments(): array { if ($this->invoicePdf !== null && $this->invoicePdfFileName !== null) { return [ Attachment::fromData(fn () => $this->invoicePdf, $this->invoicePdfFileName) ->withMime('application/pdf'), ]; } return []; } }