From e71652fbdb1760c5fbdf9fe831ccdcb5256b194a Mon Sep 17 00:00:00 2001 From: Grummfy Date: Wed, 13 Jun 2018 12:24:42 +0200 Subject: [PATCH] fix laravel/framework#22804 + adding some unit test --- Mailable.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Mailable.php b/Mailable.php index d998b0a..36f351a 100644 --- a/Mailable.php +++ b/Mailable.php @@ -118,6 +118,13 @@ class Mailable implements MailableContract, Renderable */ public $rawAttachments = []; + /** + * The attachments coming from storage disk + * + * @var array + */ + public $diskAttachments = []; + /** * The callbacks for the message. * @@ -345,6 +352,15 @@ protected function buildAttachments($message) ); } + foreach ($this->diskAttachments as $attachment) { + $storage = Container::getInstance()->make(FilesystemFactory::class)->disk($attachment['disk']); + + return $message->attachData( + $storage->get($attachment['path']), $attachment['name'] ?? basename($attachment['path']), + array_merge(['mime' => $storage->mimeType($attachment['path'])], $attachment['options']) + ); + } + return $this; } @@ -725,12 +741,10 @@ public function attachFromStorage($path, $name = null, array $options = []) */ public function attachFromStorageDisk($disk, $path, $name = null, array $options = []) { - $storage = Container::getInstance()->make(FilesystemFactory::class)->disk($disk); + $name = $name ?? basename($path); + $this->diskAttachments[] = compact('disk', 'path', 'name', 'options'); - return $this->attachData( - $storage->get($path), $name ?? basename($path), - array_merge(['mime' => $storage->mimeType($path)], $options) - ); + return $this; } /**