2017-07-24 64 views
-1

我已經設置了PaymentLink電子郵件 - 這將根據用戶輸入而有所不同。Laravel Mailable Trait - 將變量傳遞到視圖

我想,它已經到了Mailable Trait,但在email.blade視圖中,它的未定義。

我可郵寄特質看起來如下:

類PaymentLink擴展可郵寄 { 使用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]); 
} 

}

然後在刀片觀,我有以下幾點:

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

但這返回錯誤:**

未定義的變量,即鏈路

**

這是正確的做法嗎?

由於

回答

1

您可以更新此:

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

返回$這 - >視圖( 'emails.payment_link')>與([ '鏈路'=> $這 - >鏈接]);

你錯過-with

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