64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Http\Controllers\EController;
|
|
use App\Http\Controllers\PdfController;
|
|
use App\Models\Invoice;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Attachment;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class InvoiceMail extends Mailable
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
public string $body {
|
|
set {
|
|
$this->body = $value;
|
|
}
|
|
}
|
|
|
|
public string $pdf;
|
|
|
|
public string $xml;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*/
|
|
public function __construct(protected Invoice $invoice)
|
|
{
|
|
$pdf = new PdfController();
|
|
$this->pdf = $pdf->attachInvoice($invoice->id);
|
|
|
|
$xml = new EController();
|
|
$this->xml = $xml->attachInvoice($invoice->id);
|
|
}
|
|
|
|
/**
|
|
* Get the message content definition.
|
|
*/
|
|
public function content(): Content
|
|
{
|
|
return new Content(
|
|
html: 'mail.invoice.sent',
|
|
with: ['html' => $this->body],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the attachments for the message.
|
|
*/
|
|
public function attachments(): array
|
|
{
|
|
return [
|
|
Attachment::fromData(fn() => $this->pdf, __('invoice.Invoice') . '_' . $this->invoice->number . '.pdf')
|
|
->withMime('application/pdf'),
|
|
Attachment::fromData(fn() => $this->xml, __('invoice.Invoice') . '_' . $this->invoice->number . '.xml')
|
|
->withMime('application/xml'),
|
|
];
|
|
}
|
|
}
|