ldc-boutique-cnc/app/Mail/SendContactMail.php

77 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2021-04-06 12:56:54 +02:00
<?php
namespace App\Mail;
2022-09-03 16:56:16 +02:00
use App\Http\Requests\ContactFormRequest;
2021-04-06 12:56:54 +02:00
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class SendContactMail extends Mailable
{
use Queueable;
use SerializesModels;
/**
* The form data.
*
2022-09-03 16:56:16 +02:00
* @var \App\Http\Requests\ContactFormRequest
2021-04-06 12:56:54 +02:00
*/
protected $data;
/**
* The joined file name
*
* @var string
*/
protected $joinedFileName;
/**
* Create a new message instance.
*
2022-09-03 16:56:16 +02:00
* @param \App\Http\Requests\ContactFormRequest $data
2021-04-06 12:56:54 +02:00
* @return void
*/
2022-09-03 16:56:16 +02:00
public function __construct(ContactFormRequest $data)
2021-04-06 12:56:54 +02:00
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$data = $this->data;
$this->joinFileIfProvided();
return $this->subject("Contact - " . config('theme.site_name', 'Boutique') . " - " . $data->subject)
->from($data->email)
->view('mails.send-contact', compact('data'));
}
/**
* Attach a joined file if given in data
*
* @return void
*/
protected function joinFileIfProvided(): void
{
if ($this->data->file) {
$this->joinedFileName = sprintf(
'BOUTIQUE_MESSAGE-PJ-%s.%s',
date("YmdHis"),
$this->data->file->extension()
);
$this->attach($this->data->file, [
'as' => $this->joinedFileName,
'mime' => $this->data->file->getMimeType()
]);
}
}
}