build(); // Get the current user for the ID $currentUser = Auth::user(); // Build the body so we can use it as a string $bodies = $this->buildView(); /** @var HtmlString $html */ $html = $bodies['html']; /** @var HtmlString $text */ $text = $bodies['text']; return new EmailLog([ 'sender_user_id' => !is_null($currentUser) ? $currentUser->id : null, 'sender_name' => $this->from[0]['name'], 'sender_address' => $this->from[0]['address'], 'to_addresses' => json_encode($this->to), 'cc_addresses' => json_encode($this->cc), 'bcc_addresses' => json_encode($this->bcc), 'subject' => $this->subject, 'body_plain' => $text->toHtml(), 'body_html' => $html->toHtml() ]); } }