首页  >  文章  >  php框架  >  解决Laravel 8 undefined variable错误问题

解决Laravel 8 undefined variable错误问题

藏色散人
藏色散人转载
2021-11-19 16:13:242988浏览

下面由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删除