首頁 >php框架 >Laravel >解決Laravel 8 undefined variable錯誤問題

解決Laravel 8 undefined variable錯誤問題

藏色散人
藏色散人轉載
2021-11-19 16:13:243019瀏覽

下面由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中文網其他相關文章!

陳述:
本文轉載於:learnku.com。如有侵權,請聯絡admin@php.cn刪除