1.1 การวางโฟลเดอร์แบบ Domain/Action-Driven Architecture

วิดีโอบทเรียนความยาว 25 นาที (1080p HD Streaming)

บทที่ 1: สถาปัตยกรรม & Best Practices

1.1 การวางโฟลเดอร์แบบ Domain/Action-Driven Architecture

ทำไม Controller ไม่ควรมี Business Logic เกิน 10 บรรทัด? เรามาเรียนรู้วิธีการใช้ Single Action Classes และ Service Injection เพื่อให้โค้ดทดสอบง่ายและขยายขนาดได้ไร้ขีดจำกัด

code_snippet.php
<?php

namespace App\Actions;

use App\Models\User;
use App\Models\Software;
use App\Models\SoftwareLicense;
use Illuminate\Support\Str;

class GenerateSoftwareLicenseAction
{
    public function execute(User $user, Software $software): SoftwareLicense
    {
        return SoftwareLicense::create([
            'user_id' => $user->id,
            'software_id' => $software->id,
            'license_key' => 'KRU-' . strtoupper(Str::random(4)) . '-' . strtoupper(Str::random(4)),
            'activated_at' => now(),
            'is_active' => true,
        ]);
    }
}
Language: PHP กดปุ่มคัดลอกเพื่อนำโค้ดไปวางใน IDE ของคุณได้ทันที

ชุมชนถาม-ตอบประจำบทเรียน (0)

เข้าสู่ระบบเพื่อร่วมตั้งคำถาม

กรุณาเข้าสู่ระบบ หรือสมัครสมาชิกก่อนเพื่อโพสต์คำถามในบทเรียนนี้

ยังไม่มีคำถามในบทนี้ เป็นคนแรกที่เริ่มการพูดคุยได้เลย!

สารบัญบทเรียนทั้งหมด

ความคืบหน้า 0%
เรียนจบแล้ว 0 / 3 บทเรียน ยังไม่เริ่ม
เรียนอีก 3 บท เพื่อปลดล็อคใบประกาศนียบัตร

บทที่ 3: Caching, Queue และ Background Jobs