W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
如果您想要在郵件數(shù)據(jù)發(fā)送到模板前自定義它們的格式,您可以使用 with
方法來手動傳遞數(shù)據(jù)到視圖中。一般情況下,您還是需要通過 mailable 類的構(gòu)造函數(shù)來傳遞數(shù)據(jù);不過,您應(yīng)該將它們定義為 protected
或 private
以防止它們被自動傳遞到視圖中。然后,在您調(diào)用 with
方法的時候,您可以以數(shù)組的形式傳遞您想要傳遞給模板的數(shù)據(jù):
<?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;
/**
* 訂單實(shí)例。
*
* @var \App\Models\Order
*/
protected $order;
/**
* 創(chuàng)建一個消息實(shí)例。
*
* @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')
->with([
'orderName' => $this->order->name,
'orderPrice' => $this->order->price,
]);
}
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: