Spatie's laravel-pdf v2.6.0 adds the Attachable contract support to PdfBuilder, so you can pass a generated PDF directly to attach() in a mailable or notification without saving it to disk first.
PdfBuilder now implements Illuminate\Contracts\Mail\Attachable, which means any PdfBuilder instance works wherever Laravel expects an attachable. The filename comes from name() (the .pdf extension is appended automatically if missing) and the MIME type is set to application/pdf automatically.
Here's how it looks in a notification:
use Illuminate\Notifications\Messages\MailMessage;use Spatie\LaravelPdf\Facades\Pdf; public function toMail(object $notifiable): MailMessage{ $pdf = Pdf::view('pdfs.invoice', ['invoice' => $this->invoice]) ->name('invoice.pdf'); return (new MailMessage) ->subject('Your invoice') ->line('Please find your invoice attached.') ->attach($pdf);}
And in a mailable via attachments():
use Illuminate\Mail\Mailable;use Spatie\LaravelPdf\Facades\Pdf; class InvoiceMail extends Mailable{ public function __construct(public Invoice $invoice) {} public function attachments(): array { return [ Pdf::view('pdfs.invoice', ['invoice' => $this->invoice]) ->name('invoice.pdf'), ]; }}