ldc-legaulois/app/Mail/ContactMail.php

71 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2024-10-04 17:24:15 +02:00
<?php
namespace App\Mail;
use App\Models\MailContactData;
use Illuminate\Bus\Queueable;
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.
*
* @var \App\Models\MailContactData
2024-10-04 17:24:15 +02:00
*/
protected $data;
/**
* The path of a specific file.
2024-10-04 17:24:15 +02:00
*
* @var string|null
2024-10-04 17:24:15 +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;
$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
}
/**
* 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) {
return [];
}
2026-09-25 16:25:31 +02:00
return [
Attachment::fromPath($this->file)->as($this->data->joinFile),
];
}
2024-10-04 17:24:15 +02:00
}