Mailables

ตัวอย่าง Code ในการ Send Email โดยทำ Template Email ของแต่ละ Status เก็บไว้ใน Database พร้อมทั้งดึงข้อมูลจาก Template ส่งไปทาง Email ด้วย

1️⃣ Database Migrations

create_envelopes_table.php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('envelopes', function (Blueprint $table) {
            $table->id();
            $table->string('subject');
            $table->text('body');
            $table->enum('type', ['user', 'admin']);
            $table->boolean('is_sendmail');
            $table->unsignedBigInteger('status_id');
            $table->foreign('status_id')->references('id')->on('statuses');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('envelopes');
    }
};

2️⃣ Model

3️⃣ Mailable Class

4️⃣ Controller

5️⃣ View

Last updated