Home > PHP Framework > Laravel > body text

Solve Laravel 8 undefined variable error problem

藏色散人
Release: 2021-11-22 15:51:57
forward
2980 people have browsed it

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
                ]);
    }
Copy after login

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
                ]);
    }
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template