71 lines
1.5 KiB
PHP
71 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\MailContactData;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Attachment;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class ContactMail extends Mailable
|
|
{
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* The order instance.
|
|
*
|
|
* @var \App\Models\MailContactData
|
|
*/
|
|
protected $data;
|
|
|
|
/**
|
|
* The path of a specific file.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
protected $file;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @param \App\Models\MailContactData $data
|
|
* @param string|null $file
|
|
* @return void
|
|
*/
|
|
public function __construct(MailContactData $data, string|null $file = null)
|
|
{
|
|
$this->data = $data;
|
|
$this->file = $file;
|
|
}
|
|
|
|
/**
|
|
* Build the message.
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function build()
|
|
{
|
|
return $this
|
|
->subject(sprintf('Nouveau message consommateur Le Gaulois (%s)', $this->data->type->label()))
|
|
->view('emails.contact')
|
|
->text('emails.contact-plain')
|
|
->with('data', $this->data);
|
|
}
|
|
|
|
/**
|
|
* Get the attachments for the message.
|
|
*
|
|
* @return array<int, \Illuminate\Mail\Attachment>
|
|
*/
|
|
public function attachments(): array
|
|
{
|
|
if (!$this->file) {
|
|
return [];
|
|
}
|
|
return [
|
|
Attachment::fromPath($this->file)->as($this->data->joinFile),
|
|
];
|
|
}
|
|
}
|