Skip to content

Commit

Permalink
fix laravel/framework#22804 + adding some unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Grummfy committed Jul 11, 2018
1 parent 798c57c commit e71652f
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

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

/**
Expand Down

0 comments on commit e71652f

Please sign in to comment.