data = $data; } /** * @return $this */ public function build() { $this->data['url'] = route('payment', [ 'email_log' => $this->logDelivery(), ]); $payload = $this->data; $message = $this->from($payload['from'], config('mail.from.name')) ->subject($payload['subject']) ->markdown('emails.send.payment', [ // Passed as a list, not as a keyed array. The numeric keys // that produces are inert: the view reads $data, which // Laravel already supplies from the public property above. 'data', $this->data, ]); $renderer = $payload['attach']['data']; if ($renderer) { $message->attachData( $renderer->output(), $payload['payment']['payment_number'].'.pdf' ); } return $message; } /** * Write the outgoing message to the email log and give back the token * that stands in for it in a public link. */ private function logDelivery(): string { $payload = $this->data; $receipt = Payment::findOrFail($payload['payment']['id']); return app(EmailLogWriter::class)->record($receipt, [ 'from' => $payload['from'], 'to' => $payload['to'], 'cc' => $payload['cc'] ?? null, 'bcc' => $payload['bcc'] ?? null, 'subject' => $payload['subject'], 'body' => $payload['body'], ]); } }