From 7333c8aabbd3c03485a71c0e87966424c602562c Mon Sep 17 00:00:00 2001 From: ReeceM Date: Thu, 3 Nov 2022 17:06:29 +0200 Subject: [PATCH 1/3] fix: compatible way to call the method on mailable --- src/MailEclipse.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MailEclipse.php b/src/MailEclipse.php index 5077d03..019c230 100644 --- a/src/MailEclipse.php +++ b/src/MailEclipse.php @@ -802,12 +802,14 @@ protected static function getMarkdownViewName($mailable) */ public static function buildMailable($instance, $type = 'call') { + $method = method_exists($instance, 'build') ? 'build' : 'render'; + if ($type === 'call') { if (self::handleMailableViewDataArgs($instance) !== null) { - return app()->call([self::handleMailableViewDataArgs($instance), 'build']); + return app()->call([self::handleMailableViewDataArgs($instance), $method]); } - return app()->call([new $instance, 'build']); + return app()->call([new $instance, $method]); } return app()->make($instance); From 6b3ab7e4e21bfc669c50900f1971e3fd4195f577 Mon Sep 17 00:00:00 2001 From: ReeceM Date: Sat, 19 Nov 2022 15:31:39 +0200 Subject: [PATCH 2/3] use buildViewData and also content methods --- src/MailEclipse.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/MailEclipse.php b/src/MailEclipse.php index 019c230..920f4c7 100644 --- a/src/MailEclipse.php +++ b/src/MailEclipse.php @@ -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); @@ -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); } @@ -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]); } @@ -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) { From 9dd0b5c03312e1e11769e2e15daaaf65448d3f9f Mon Sep 17 00:00:00 2001 From: ReeceM Date: Sat, 19 Nov 2022 15:50:39 +0200 Subject: [PATCH 3/3] wip --- src/MailEclipse.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MailEclipse.php b/src/MailEclipse.php index 920f4c7..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; @@ -810,7 +813,7 @@ public static function buildMailable($instance, $type = 'call') if ($type === 'call') { if (self::handleMailableViewDataArgs($instance) !== null) { - return app()->call([self::handleMailableViewDataArgs($instance), $method]); + return self::handleMailableViewDataArgs($instance); } if ($method == 'content') {