Laravel 8 從磁盤中添加附件

2021-07-19 10:47 更新

如果您已在 文件存儲 上存儲了一個文件,則可以使用 attachFromStorage 方法將其附加到電子郵件中:

/**
 * 構(gòu)建消息
 *
 * @return $this
 */
public function build()
{
   return $this->view('emails.orders.shipped')
               ->attachFromStorage('/path/to/file');
} 

如有必要,您可以使用 attachFromStorage 方法的第二個和第三個參數(shù)指定文件的附件名稱和其他選項:

/**
 * 構(gòu)建消息
 *
 * @return $this
 */
public function build()
{
   return $this->view('emails.orders.shipped')
               ->attachFromStorage('/path/to/file', 'name.pdf', [
                   'mime' => 'application/pdf'
               ]);
} 

如果需要指定默認(rèn)磁盤以外的存儲磁盤,可以使用 attachFromStorageDisk 方法:

/**
 * 構(gòu)建消息
 *
 * @return $this
 */
public function build()
{
   return $this->view('emails.orders.shipped')
               ->attachFromStorageDisk('s3', '/path/to/file');
} 


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號