一般Eamil
- 建立Email
php artisan make:mail OrderShipped
-
寄送
use App\Mail\xxx; // 前面建立的Email use App\Model\xxx; // Email的資料來源 use Illumunate\Support\Facades\Mail; // Email功能 class RunEmailCommand { // get source $data = ${Modle}::all()->random(); Mail::to(${收件人})->send(new ${Email設定}($data)); }
Markdown Email
建立Email
php artisan make:mail OrderShipped --markdown=emails.orders.shipped
-markdown=...
是 Artisan 指令的參數,用來告訴 Laravel:
> 幫我建立一個 Mailable 類別,而且要搭配指定的 Markdown 檢視檔案。
>emails.orders.shipped
會對應到 Blade 檔案:resources/views/emails/orders/shipped.blade.php
建立元件
php artisan make:component Alert
INFO Component [app/View/Components/Alert.php] created successfully.
INFO View [resources/views/components/Alert.blade.php] created successfully
- Component
- 元件相關邏輯
- 元件資料注入
- View
- 顯示Blade
- 在Email Blade 中引用component
<div> <x-header/> </div> <x-alert />
官網文件
小記
- laravel 有建議把content根envolope分開設置
- view可以引用model注入參數
- view可以根據前面寄信丟過來的資料取得對應資料
- view model引用數量不限制,但建議可以用cache減少DB耗能(如果是經常不變動的部分)