我正在向电子邮件发送多个附件。它们来自存储磁盘以及远程源。我想先显示磁盘文件,然后再显示远程文件。
build()
方法:public function build()
{
// Attaching Disk File First
$this->attachFromStorageDisk('public', '/path/to/myfiel.pdf');
// Attaching Remote Files
foreach ($this->files as $file) {
$this->attach($file);
}
return $this->view('email.orders.shipped');
}
我优先使用buildAttachments
方法来生成存储磁盘文件:
buildAttachments
方法:protected function buildAttachments( $message )
{
$this->buildDiskAttachments( $message ); // <-- Brought this one top to build disk attachment first
foreach ( $this->attachments as $attachment ) {
$message->attach( $attachment['file'], $attachment['options'] );
}
foreach ( $this->rawAttachments as $attachment ) {
$message->attachData(
$attachment['data'], $attachment['name'], $attachment['options']
);
}
return $this;
}
我的磁盘文件是PDF
。远程文件可以混合使用pdf/png/jpg/jpeg
。当所有远程文件均为pdf
时,附件顺序工作正常。
但是,如果有image file(jpg/jpeg/png)
,则总是优先。
Mailable
课程:class OrderShipped extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
protected $files;
public function __construct($files)
{
$this->files = $files;
}
public function build()
{
// Attaching Disk File First
$this->attachFromStorageDisk( 'public', '/path/to/myfiel.pdf' );
// Attaching Remote Files
foreach ( $this->files as $file ) {
$this->attach( $file );
}
return $this->view( 'email.orders.shipped' );
}
/**
* Add all of the attachments to the message.
*
* @param \Illuminate\Mail\Message $message
*
* @return $this
*/
protected function buildAttachments( $message )
{
$this->buildDiskAttachments( $message ); // <-- Brought this one top to build disk attachment first
foreach ( $this->attachments as $attachment ) {
$message->attach( $attachment['file'], $attachment['options'] );
}
foreach ( $this->rawAttachments as $attachment ) {
$message->attachData(
$attachment['data'], $attachment['name'], $attachment['options']
);
}
return $this;
}
}
现在,无论我附加的远程文件类型如何,我总是希望
PDF File
中的Storage Disk
显示为FIRST。你能帮忙吗?
Laravel版本:6.18.16