Services
Ringkasan
Services berisi business logic yang diekstrak dari controllers dan models. Berlokasi di app/Services/, diorganisir per domain.
Struktur Folder
app/Services/
├── Asset/ # Upload file + CDN (ImageKitService, CompressService, dll)
├── Codegen/ # Barcode + QR (GenerateBarcode, GenerateQRCode)
├── Common/ # Lintas domain (IdentifierAppService)
├── Otp/ # OTP (Generate, Verify)
└── Platform/ # Pipeline orchestrationPattern
Single-Action Service
Satu class untuk satu aksi. Pakai method handle().
php
class Generate
{
public static function handle(string $email, array $meta = []): Otp { ... }
}
// Panggil: Generate::handle($email)Multi-Method Service
Satu class untuk beberapa operasi terkait.
php
class ImageKitService
{
public function prepare(...) { ... }
public function upload(...) { ... }
}
// Panggil: app(ImageKitService::class)->prepare(...)Aturan
- No HTTP concerns — service tidak sentuh request/response/session
- Stateless — semua state di models atau stores
- Injectable — constructor injection untuk dependencies
- Testable — bisa di-test tanpa Laravel bootstrapping
File Penting
| File | Tujuan |
|---|---|
app/Services/Asset/ImageKitService.php | Upload + CDN |
app/Services/Otp/Generate.php | Generate OTP |
app/Services/Common/IdentifierAppService.php | Pengecekan state aplikasi |