简体   繁体   中英

Laravel Mailable Trait - Pass a variable into view

I have set up a PaymentLink Email - This will differ pending on user input.

I think, It's gone to the Mailable Trait, But in the email.blade view, Its coming up undefined.

My Mailable Trait looks as follows :

class PaymentLink extends Mailable { use Queueable, SerializesModels;

/**
 * Create a new message instance.
 *
 * @return void
 */

protected $link;

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

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->view('emails.payment_link')>with(['link' => $this->link]);
}

}

Then in the blade view, I have the following :

<a href="{{ $link }}" target="_blank"><img src="{{asset('/assets/img/emails/button-payment.png')}}" alt="Make Payment" /></a>

But this is returning the error : **

Undefined variable: link

**

Is this the right approach?

Thanks

You can update this :

public function build()
{
    return $this->view('emails.payment_link')->with(['link' => $this->link]);
}

return $this->view('emails.payment_link')>with(['link' => $this->link]);

You miss - before with :

return $this->view('emails.payment_link')->with(['link' => $this->link]);
                                         ^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM