Files
kreios/backoffice/app/Mail/PreventivoCliente.php

53 lines
1.2 KiB
PHP

<?php
namespace App\Mail;
use App\Models\Preventivo;
use App\Support\PreventivoPdf;
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 PreventivoCliente extends Mailable
{
use Queueable, SerializesModels;
public function __construct(public Preventivo $preventivo)
{
}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Il tuo preventivo Krèios n. '.$this->preventivo->numero,
);
}
public function content(): Content
{
return new Content(
markdown: 'emails.preventivo-cliente',
with: ['preventivo' => $this->preventivo],
);
}
/** @return array<int, Attachment> */
public function attachments(): array
{
$path = PreventivoPdf::pathAssoluto($this->preventivo);
if (! $path) {
return [];
}
return [
Attachment::fromPath($path)
->as('preventivo-'.$this->preventivo->numero.'.pdf')
->withMime('application/pdf'),
];
}
}