解决Laravel 8 undefined variable错误问题
时间:2021-11-22 15:51
下面由Laravel教程栏目带大家介绍如何解决Laravel 8 使用mailable发送邮件,undefined variable错误问题,希望对大家有所帮助!
具体问题:
Laravel 8 使用mailable发送邮件,undefined variable错误?
Laravel 8 使用 mailable 的方法发送邮件,一直出现 undefined variable 的错误,但是参照网上的解决方案,使用 public 定义 variable,但是还是报同样的错误
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 ]); }
解决办法:
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 ]); }
以上就是解决Laravel 8 undefined variable错误问题的详细内容,更多请关注gxlsystem.com其它相关文章!