The following tutorial column of Laravel will introduce how to solve the problem of undefined variable error when using mailable to send emails in Laravel 8. I hope it will be helpful to everyone!
Specific question:
Laravel 8 uses mailable to send emails, undefined variable error?
Laravel 8 uses the mailable method to send emails, and the error of undefined variable keeps appearing. However, according to the online solution, I use public to define the variable, but I still get the same error
public $jobdocumentmessage; /** * Create a new message instance. * * @return void */ public function __construct($jobdocumentmessage) { $this->jobdocumentmessage = $jobdocumentmessage; } /** * Build the message. * * @return $this */ public function build() { #dd($jobdocumentmessage); return $this->view('emails.jobDocument') ->with([ 'body' => $jobdocumentmessage->body, 'user' => $jobdocumentmessage->user, ]) ->subject($jobdocumentmessage->subject) ->replyTo($jobdocumentmessage->mail) ->attach($jobdocumentmessage->url, ['as' => $jobdocumentmessage->name ]); }
Solution:
public $jobdocumentmessage; /** * Create a new message instance. * * @return void */ public function __construct($jobdocumentmessage) { $this->jobdocumentmessage = $jobdocumentmessage; } /** * Build the message. * * @return $this */ public function build() { $jobdocumentmessage= $this->jobdocumentmessage ; return $this->view('emails.jobDocument') ->with([ 'body' => $jobdocumentmessage->body, 'user' => $jobdocumentmessage->user, ]) ->subject($jobdocumentmessage->subject) ->replyTo($jobdocumentmessage->mail) ->attach($jobdocumentmessage->url, ['as' => $jobdocumentmessage->name ]); }
The above is the detailed content of Solve Laravel 8 undefined variable error problem. For more information, please follow other related articles on the PHP Chinese website!