Skip to content

Commit

Permalink
add attachFromStorage to mailables
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 7, 2018
1 parent 98fdbb0 commit 0fa361d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 0fa361d

Please sign in to comment.