data = $data; } /** * @return $this */ public function build() { $this->data['url'] = route('estimate', [ 'email_log' => $this->logDelivery(), ]); $payload = $this->data; $message = $this->from($payload['from'], config('mail.from.name')) ->subject($payload['subject']) ->markdown('emails.send.estimate', [ // Handed over 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, ]); $pdf = $payload['attach']['data']; if ($pdf) { $message->attachData( $pdf->output(), $payload['estimate']['estimate_number'].'.pdf' ); } return $message; } /** * Record the outgoing message and give back the token that identifies it * in a public link. */ private function logDelivery(): string { $payload = $this->data; $alias = ModelIdentityMap::aliasFor(Estimate::class); $log = EmailLog::create([ 'from' => $payload['from'], 'to' => $payload['to'], 'cc' => $payload['cc'] ?? null, 'bcc' => $payload['bcc'] ?? null, 'subject' => $payload['subject'], 'body' => $payload['body'], 'mailable_type' => $alias, 'mailable_id' => $payload['estimate']['id'], ]); $log->token = Hashids::connection(HashidConnection::EmailLog->value) ->encode($log->id); $log->save(); return $log->token; } }