Cowgirl
Cowgirl

Reputation: 1494

Sending value from controller to Mail to view

In my controller, I am trying send mail like this

$activationLink = $activation->GetActivationCode->ActivationLink;
\Mail::to($company)->send(new MLink);

I have a variable called activationlink, which I need to send it to the email

Mlink Mail class

public function build()
    {
        return $this->view('emails.mindbody')->with($activationLink);
    }

View file

<h2>Your activation link is : {{ $activationlink }} </h2>

It's not working this way, I get the activationlink is not defined error.

How can I pass the $activationLink from my controller, to the view file (the email that is sent)?

Upvotes: 1

Views: 44

Answers (1)

Maraboc
Maraboc

Reputation: 11083

You can add it in the constructor of MLink class like this :

private $activationLink;

public function __construct($activationLink)
{
    $this->activationLink = $activationLink;
}

public function build()
{
    return $this->view('emails.mindbody')->with($this->activationLink);
}

And in the controller

$activationLink = $activation->GetActivationCode->ActivationLink;
\Mail::to($company)->send(new MLink($activationLink));

Or as mentioned by @Camilo you can set the visibility of $activationLink to public and remove ->with keyword because you will have access to this variable in the view :)

Upvotes: 2

Related Questions