เมื่อแอปพลิเคชัน Laravel เติบโตขึ้น แนวทาง "fat controller / fat model" แบบเริ่มต้นจะดูแลรักษาได้ยาก แอปขนาดใหญ่ได้ประโยชน์จาก เลเยอร์สถาปัตยกรรมเพิ่มเติม เช่น service classes, action classes, repositories, form requests และการจัดระเบียบ domain ที่ชัดเจน เพื่อรักษาให้ business logic เป็นระเบียบ ทดสอบได้ และดูแลรักษาได้
ปัญหา: ลอจิกไปอยู่ผิดที่
Small apps: logic in controllers and models is fine.
Large apps: controllers get bloated, models become "god objects", logic is duplicated
→ hard to test, maintain, and reason about. Extract logic into dedicated layers.
service classes — ห่อหุ้ม business logic
{
{}
{
DB::(function () ($, $) { /* ... */ });
}
}
{
->(->(), ->());
}
