Skip to content

Commit 0fa361d

Browse files
committed
add attachFromStorage to mailables
1 parent 98fdbb0 commit 0fa361d

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/Illuminate/Mail/Mailable.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Illuminate\Contracts\Translation\Translator;
1616
use Illuminate\Contracts\Mail\Mailer as MailerContract;
1717
use Illuminate\Contracts\Mail\Mailable as MailableContract;
18+
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
1819

1920
class Mailable implements MailableContract, Renderable
2021
{
@@ -703,6 +704,38 @@ public function attach($file, array $options = [])
703704
return $this;
704705
}
705706

707+
/**
708+
* Attach a file to the message from storage.
709+
*
710+
* @param string $path
711+
* @param string $name
712+
* @param array $options
713+
* @return $this
714+
*/
715+
public function attachFromStorage($path, $name = null, array $options = [])
716+
{
717+
return $this->attachFromStorageDisk(null, $path, $name, $options);
718+
}
719+
720+
/**
721+
* Attach a file to the message from storage.
722+
*
723+
* @param string $disk
724+
* @param string $path
725+
* @param string $name
726+
* @param array $options
727+
* @return $this
728+
*/
729+
public function attachFromStorageDisk($disk, $path, $name = null, array $options = [])
730+
{
731+
$storage = Container::getInstance()->make(FilesystemFactory::class)->disk($disk);
732+
733+
return $this->attachData(
734+
$storage->get($path), $name ?? basename($path),
735+
array_merge(['mime' => $storage->mimeType($path)], $options)
736+
);
737+
}
738+
706739
/**
707740
* Attach in-memory data as an attachment.
708741
*

0 commit comments

Comments
 (0)