Laravel mPDF mail attachment error "Illuminate\Mail\Attachment::fromData(): Argument #1 ($data) must be of type Closure, string given"
16:28 03 Jun 2024

Hi I'm trying make a function to send an email and attach a .pdf file by using the dependency laravel mPDF

My mail object where the error happends is in the attachments() function:

class TIPoliciesMail extends Mailable
{
  // ...
  public function attachments(): array
  {
     $pdf = pdf::loadView('pdf.basics.ti-policies-pdf');
      return [
         Attachment::fromData($pdf->output(), 'doc.pdf')->withMime('application/pdf')
      ];
  }
  // ...
}

This is the error message Error image message

I want to know what's a Closure type because the error tells, that is because a string is given instead of a Closure, I don't know if the error occurs in the function $pdf->output()

laravel mpdf laravel-mail