W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
通常情況下,您可能想要在渲染郵件的 HTML 內(nèi)容時傳遞一些數(shù)據(jù)到視圖中。有兩種方法傳遞數(shù)據(jù)到時視圖中。第一種,您在 mailable 類中定義的所有 public 的屬性都將自動傳遞到視圖中。因此,舉個例子,您可以將數(shù)據(jù)傳遞到您的 mailable 類的構(gòu)造函數(shù)中,并將其設(shè)置為類的 public 屬性:
<?php
namespace App\Mail;
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class OrderShipped extends Mailable
{
use Queueable, SerializesModels;
/**
* 訂單實例。
*
* @var Order
*/
public $order;
/**
* 創(chuàng)建一個消息實例。
*
* @param \App\Models\Order $order
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* 構(gòu)造消息。
*
* @return $this
*/
public function build()
{
return $this->view('emails.orders.shipped');
}
}
當數(shù)據(jù)被設(shè)置成為 public 屬性之后,它將被自動傳遞到您的視圖中,因此您可以像您在 Blade 模板中那樣訪問它們:
<div>
Price: {{ $order->price }}
</div>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: