diff --git a/src/MailEclipse.php b/src/MailEclipse.php index 5077d03..ebee7bc 100644 --- a/src/MailEclipse.php +++ b/src/MailEclipse.php @@ -553,7 +553,10 @@ protected static function mailablesList() $collection = collect($fqcns)->map(function ($mailable) { return $mailable; })->reject(function ($object) { - return ! method_exists($object['namespace'], 'build'); + return ! array_search( + 'Illuminate\Contracts\Mail\Mailable', + class_implements($object['namespace'] + )); }); return $collection; @@ -713,7 +716,7 @@ private static function getMailableViewData($mailable, $mailable_data) $classProps = array_diff($allProps, $traitProperties); - $withFuncData = collect($obj->viewData)->keys(); + $withFuncData = collect($obj->buildViewData())->keys(); $mailableData = collect($classProps)->merge($withFuncData); @@ -789,6 +792,10 @@ protected static function getMarkdownViewName($mailable) $property->setAccessible(true); + if (method_exists($mailable, 'content')) { + return app()->call([new $mailable, 'content'])->markdown; + } + return $property->getValue($mailable); } @@ -802,12 +809,22 @@ protected static function getMarkdownViewName($mailable) */ public static function buildMailable($instance, $type = 'call') { + $method = method_exists($instance, 'build') ? 'build' : 'content'; + if ($type === 'call') { if (self::handleMailableViewDataArgs($instance) !== null) { - return app()->call([self::handleMailableViewDataArgs($instance), 'build']); + return self::handleMailableViewDataArgs($instance); + } + + if ($method == 'content') { + /** @var \Illuminate\Mail\Mailable */ + $class = new $instance; + $class->view(app()->call([new $instance, 'content'])->view); + + return $class; } - return app()->call([new $instance, 'build']); + return app()->call([new $instance, $method]); } return app()->make($instance); @@ -831,7 +848,7 @@ public static function renderPreview($simpleview, $view, $template = false, $ins if (! $template) { $obj = self::buildMailable($instance); - $viewData = $obj->viewData; + $viewData = $obj->buildViewData(); $_data = array_merge($instance->buildViewData(), $viewData); foreach ($_data as $key => $value) {