Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
use buildViewData and also content methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeceM committed Nov 19, 2022
1 parent 7333c8a commit 6b3ab7e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/MailEclipse.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,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);

Expand Down Expand Up @@ -789,6 +789,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);
}

Expand All @@ -802,13 +806,21 @@ protected static function getMarkdownViewName($mailable)
*/
public static function buildMailable($instance, $type = 'call')
{
$method = method_exists($instance, 'build') ? 'build' : 'render';
$method = method_exists($instance, 'build') ? 'build' : 'content';

if ($type === 'call') {
if (self::handleMailableViewDataArgs($instance) !== null) {
return app()->call([self::handleMailableViewDataArgs($instance), $method]);
}

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, $method]);
}

Expand All @@ -833,7 +845,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) {
Expand Down

0 comments on commit 6b3ab7e

Please sign in to comment.