Sharim's avatar

Send Attachment with Email in Laravel

I'm trying to send an email with pdf attachment in Laravel but I'm getting error,

My Mail is:

use Illuminate\Mail\Mailables\Attachment;

public function build(Request $request)
    {
        return [
            Attachment::fromStorage('/brochures')
                    ->as($request->b_code.'.pdf')
                    ->withMime('application/pdf'),
        ];
    }

Controller:

use Mail;
Mail::to('[email protected]')->send(new Brochure($request));

But I'm getting this error:

Class 'Illuminate\Mail\Mailable\Attachment' not found

0 likes
8 replies
Sinnbeck's avatar

I think it should be

use Illuminate\Mail\Attachment;

Edit: Ah it is also in mailables in the newest version. Run composer update

1 like
Sharim's avatar

@Sinnbeck I've run composer update. But still the same error:

Class 'Illuminate\Mail\Attachment' not found

Sharim's avatar

@Sinnbeck I'm sending the emails on the same project, but first time sending it with attachment. Is there any alternative way to send attachments?

Sinnbeck's avatar

@Sharim That is not the same error? But it should work with either version now.

Please or to participate in this conversation.