Send attachment in an email

Hello, how can I send an attachment?

I created some functions for sending emails including attachments.

Custom Endpoint:

// Send an email using Mailable with a qualified namespace
        \ Illuminate\Support\Facades\Mail::to($receiver)
            ->send(new \App\Mail\SendtoAll($message, $pdf));

In the app, I created a new folder called Mail and it looks like this:

<? php
// app/Mail/SendtoAll.php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Available;
use Illuminate\Queue\SerializesModels;
use Barryvdh\DomPDF\PDF as DomPDF;

class SendtoAll extends Mailable
{
    using Queueable, SerializesModels;

    public $period; public $period
    public $pdf;

    public function __construct($message, DomPDF $pdf)
    {
        $this->period = $message['period'];
        $this->pdf = $pdf;
    }

    public function build()
    {
		$filename = 'SAFETY PATROL FINDINGS - ' . $this->period;
        $subject = '[' . $this->period . ']-Safety Patrol Findings';

        return $this->subject($subject)
			->view('emails.sendtoall')
            ->attachData($this->pdf->output(), $filename . '.pdf', [
                'mime' => 'application/pdf',
            ]);
    }
}

Finally, I created an html view like this for the body of the email:

<!-- resources/views/emails/sendtoall.blade.php -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Record Action Email</title>
</head>
<body>
    <p>Dear All,</p>
    
    ...
	
	<p>This email was sent from the HSE MKAI application, please don't reply to this email.</p>
    
    <p>Thanks & Regards</p>
</body>
</html>

Hope that helps