Skip to content

Instantly share code, notes, and snippets.

@richardDobron
Created July 11, 2022 17:57
Show Gist options
  • Save richardDobron/1a9235b5db64ff06718c2261c7e56c53 to your computer and use it in GitHub Desktop.
Save richardDobron/1a9235b5db64ff06718c2261c7e56c53 to your computer and use it in GitHub Desktop.
<?php
use App\Mail\Traits;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Support\HtmlString;
use Soundasleep\Html2Text;
trait TextMailBuilder
{
protected function buildView()
{
if (isset($this->html)) {
if (! $this->textView) {
$plainText = Html2Text::convert($this->html);
$text = new HtmlString($plainText);
} else {
$text = $this->textView;
}
return array_filter([
'html' => new HtmlString($this->html),
'text' => $text,
]);
}
if (isset($this->markdown)) {
return $this->buildMarkdownView();
}
if (isset($this->view, $this->textView)) {
return [$this->view, $this->textView];
} elseif (isset($this->textView)) {
return ['text' => $this->textView];
}
return $this->view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment