阅读(1595) (0)

Laravel 8 附件

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

要在邮件中加入附件,在 build 方法中使用 attach 方法。attach 方法接受文件的绝对路径作为它的第一个参数:

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

附加文件到消息时,你也可以传递 数组attach 方法作为第二个参数,以指定显示名称和 / 或是 MIME 类型:

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