Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Illegal string offset 'file' on line 342, file Illuminate/Mail/Mailable.php

Tags:

php

laravel

I am trying to attach some documents to an email, using Laravel's attachFromStorageDisk method, that I read about in the documentation: Mail - Laravel.

public function build()
{
    $email = $this->view('emails.message')
        ->subject($this->emailSubject);

    foreach ($this->attachments as $attachment) {
        $email->attachFromStorageDisk('filemanager', $attachment);
    }

    return $email;
}

And the error I'm getting is this Illegal string offset 'file' on line 342, file Illuminate/Mail/Mailable.php and I can't figure out a way to fix this.

$this->attachments is an array containing the paths to the files I want to attach to the e-mail, and all the paths are correct.

Do you guys have any idea how to solve this? I couldn't find much about this specific error on line 342, Mailable.php

Thanks!

like image 735
Daniel R. Avatar asked Jan 18 '19 23:01

Daniel R.


1 Answers

Change the name of your variable $this->attachments to something else

Mailable class already has property $attachments, which you are overwriting.

like image 91
ljubadr Avatar answered Oct 19 '22 17:10

ljubadr