下面由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錯誤問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!