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

Commit

Permalink
Merge pull request #219 from Qoraiche/218-method-build-does-not-exist
Browse files Browse the repository at this point in the history
fix: compatible way to call the method on mailable
  • Loading branch information
ReeceM authored Nov 21, 2022
2 parents 8a38e3c + 9dd0b5c commit 51a3efd
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/MailEclipse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 51a3efd

Please sign in to comment.