diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index ff6787cfb80a..81506b177999 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -15,6 +15,7 @@ use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\Mail\Mailer as MailerContract; use Illuminate\Contracts\Mail\Mailable as MailableContract; +use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory; class Mailable implements MailableContract, Renderable { @@ -703,6 +704,38 @@ public function attach($file, array $options = []) return $this; } + /** + * Attach a file to the message from storage. + * + * @param string $path + * @param string $name + * @param array $options + * @return $this + */ + public function attachFromStorage($path, $name = null, array $options = []) + { + return $this->attachFromStorageDisk(null, $path, $name, $options); + } + + /** + * Attach a file to the message from storage. + * + * @param string $disk + * @param string $path + * @param string $name + * @param array $options + * @return $this + */ + public function attachFromStorageDisk($disk, $path, $name = null, array $options = []) + { + $storage = Container::getInstance()->make(FilesystemFactory::class)->disk($disk); + + return $this->attachData( + $storage->get($path), $name ?? basename($path), + array_merge(['mime' => $storage->mimeType($path)], $options) + ); + } + /** * Attach in-memory data as an attachment. *