Files
portal-api/app/Mail/CreateVirtualMachine.php
T

89 lines
2.8 KiB
PHP

<?php
namespace App\Mail;
use App\Models\Template;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class CreateVirtualMachine extends Mailable
{
use Queueable, SerializesModels;
protected $template = null;
protected $data;
protected ?string $invoicePdf = null;
protected ?string $invoicePdfFileName = null;
public function __construct($template = 0, $data = [], ?string $invoicePdf = null, ?string $invoicePdfFileName = null)
{
$this->data = $data;
$this->template = Template::find($template);
$this->invoicePdf = $invoicePdf;
$this->invoicePdfFileName = $invoicePdfFileName;
}
public function envelope()
{
return new Envelope(
subject: str_replace("{\$os_name}", $this->data['os_name'], $this->template->subject),
);
}
public function content()
{
return new Content(
view: 'emails.template',
with: [
'template' => str_replace(
[
"{\$company_name}",
"{\$company_logo}",
"{\$client_name}",
"{\$product_name}",
"{\$product_billing}",
"{\$product_price}",
"{\$service_host}",
"{\$service_username}",
"{\$service_port}",
"{\$service_password}",
"{\$os_name}",
"{\$service_due_exp}"
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['client_name'],
$this->data['product_name'],
$this->data['product_billing'],
$this->data['product_price'],
$this->data['service_host'],
$this->data['service_username'],
$this->data['service_port'],
$this->data['service_password'],
$this->data['os_name'],
$this->data['service_due_exp'],
],
$this->template->message)
]
);
}
public function attachments(): array
{
if ($this->invoicePdf !== null && $this->invoicePdfFileName !== null) {
return [
Attachment::fromData(fn () => $this->invoicePdf, $this->invoicePdfFileName)
->mime('application/pdf'),
];
}
return [];
}
}