Laravel Vietnam Meetup (August 2022) at Ho Chi Minh City, Vietnam
Your Code IsSIMPLIFY Or COMPLEXITY?with Dinh Quoc Han
View Slide
Code Của BạnĐƠN GIẢN Hay PHỨC TẠP?với Đinh Quốc Hân
Who Am I?PHP Lover, Artisan6 years experienceCurrently working at SHIFT ASIAAdmin at Laravel Viet Nam
Overview1. Problems2. Coding Standards3. CRUD4. Complexity?5. Q&A
1. Problems!
2. Coding Standards
PSR-12
How to follow PSR-12?
composer require --dev laravel/pint
3. CRUDCreate - Read - Update - Delete 😎
How Many?
M-V-C
M-V-C but by Packages
Domain Oriented DesignNot ‘DDD’ - Domain Driven Design 🤣
…
Basic Example
routes/web.php
app/Http/Controllers/UserController.php
Write all business logic in controller?
Why?
Controller should hold ZERO logic!
Controller only bring logic together!
Easy apply design patterns, structures!
Easy to reuse, maintenance, testing
1. Fat Model - Thin Controller
2. Repository Class or Service Class
3. Actions/Commands Class (CQRS)
4. Together
Example From Laravel
Next: Controller!
Cruddy by DesignAdam Wathan
"More controllers doing lesswork obviates need for manyother fancy patterns!"David Heinemeier Hansson - Creator of RoR
7 Standard Actions in Laravel
1. Index2. Create3. Store4. Show5. Edit6. Update7. Destroy
NEVER write CUSTOM ACTION
Tip #1: Nested Resource?Create New Controller
Tip #2: Edited Dependently?Create New Controller
Tip #3: Touches Pivot Records?Create New Controller
Tip #4: Transitions State?Create New Controller
Or Single Action Controller?Invokable Controller
4. Complexity?
YAGNI"You aren't gonna need it"
Back To The BASIC
1 Phút Quảng Cáo!
Thank YouQ&A