2024-10-04 17:24:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Mail;
|
|
|
|
|
|
|
|
|
|
use App\Models\MailContactData;
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
2024-10-09 17:19:20 +02:00
|
|
|
use Illuminate\Mail\Attachment;
|
2024-10-04 17:24:15 +02:00
|
|
|
use Illuminate\Mail\Mailable;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
|
|
class ContactMail extends Mailable
|
|
|
|
|
{
|
|
|
|
|
use Queueable;
|
|
|
|
|
use SerializesModels;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The order instance.
|
|
|
|
|
*
|
2024-09-26 17:39:57 +02:00
|
|
|
* @var \App\Models\MailContactData
|
2024-10-04 17:24:15 +02:00
|
|
|
*/
|
|
|
|
|
protected $data;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-10-09 17:19:20 +02:00
|
|
|
* The path of a specific file.
|
2024-10-04 17:24:15 +02:00
|
|
|
*
|
2024-10-09 17:19:20 +02:00
|
|
|
* @var string|null
|
2024-10-04 17:24:15 +02:00
|
|
|
*/
|
2024-10-09 17:19:20 +02:00
|
|
|
protected $file;
|
2024-10-04 17:24:15 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new message instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function __construct(MailContactData $data, ?string $file = null)
|
2024-10-04 17:24:15 +02:00
|
|
|
{
|
|
|
|
|
$this->data = $data;
|
2024-10-09 17:19:20 +02:00
|
|
|
$this->file = $file;
|
2024-10-04 17:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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')
|
2025-08-25 12:53:24 +02:00
|
|
|
->with('data', $this->data);
|
2024-10-04 17:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-09 17:19:20 +02:00
|
|
|
/**
|
|
|
|
|
* Get the attachments for the message.
|
|
|
|
|
*
|
|
|
|
|
* @return array<int, \Illuminate\Mail\Attachment>
|
|
|
|
|
*/
|
|
|
|
|
public function attachments(): array
|
|
|
|
|
{
|
2026-09-25 16:25:31 +02:00
|
|
|
if (! $this->file) {
|
2024-10-09 17:19:20 +02:00
|
|
|
return [];
|
|
|
|
|
}
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-10-09 17:19:20 +02:00
|
|
|
return [
|
2024-11-18 12:48:43 +01:00
|
|
|
Attachment::fromPath($this->file)->as($this->data->joinFile),
|
2024-10-09 17:19:20 +02:00
|
|
|
];
|
|
|
|
|
}
|
2024-10-04 17:24:15 +02:00
|
|
|
}
|