71 lines
1.7 KiB
PHP

<?php
namespace App\Mail;
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 DocumentMail extends Mailable
{
use Queueable, SerializesModels;
public $document;
public $type;
public $pdfContent;
/**
* Create a new message instance.
*/
public function __construct($document, string $type, $pdfContent)
{
$this->document = $document;
$this->type = $type;
$this->pdfContent = $pdfContent;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
$subject = $this->type === 'quote'
? "Votre devis Thanasoft : " . $this->document->reference
: "Votre facture Thanasoft : " . $this->document->invoice_number;
return new Envelope(
subject: $subject,
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.document',
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
$filename = $this->type === 'quote'
? 'Devis_' . $this->document->reference . '.pdf'
: 'Facture_' . $this->document->invoice_number . '.pdf';
return [
Attachment::fromData(fn () => $this->pdfContent, $filename)
->withMime('application/pdf'),
];
}
}