阅读(3014) (0)

Laravel 8 从磁盘中添加附件

2021-07-05 17:12:39 更新

如果您已在 文件存储 上存储了一个文件,则可以使用 attachFromStorage 方法将其附加到电子邮件中:

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

如有必要,您可以使用 attachFromStorage 方法的第二个和第三个参数指定文件的附件名称和其他选项:

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

如果需要指定默认磁盘以外的存储磁盘,可以使用 attachFromStorageDisk 方法:

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