Codegen
Direktori: app/Services/Codegen/
Layanan generate Barcode dan QR Code. Menghasilkan gambar PNG dari konten string.
Ringkasan
| Service | Tipe | Output | Penggunaan |
|---|---|---|---|
GenerateBarcode | 1D Barcode (C128, EAN13, dll) | PNG binary | ID siswa, label buku, tag aset |
GenerateQRCode | QR Code | PNG binary | Link scan cepat, absensi, kode pembayaran |
Kenapa Ada
- Terpusat: Satu tempat untuk semua generate barcode/QR
- Konsisten: Opsi encoding dan error handling yang sama
- Testable: Service bisa di-mock tanpa menyentuh controller
Method
GenerateBarcode::generate($content, $type = 'C128', $width = 2, $height = 30): string
Generate barcode 1D PNG.
php
$barcode = app(GenerateBarcode::class);
$png = $barcode->generate('STU-2026-001', 'C128', 2, 50);GenerateQRCode::generate($content, $size = 120, $color = [0, 0, 0]): string
Generate QR Code PNG.
php
$qr = app(GenerateQRCode::class);
$png = $qr->generate('https://sutomo.sch.id/001', 200, [0, 0, 0]);Cara Pakai
php
// Simpan sebagai Asset
$asset = new Asset;
$asset->uploadedFile = $png;
$asset->uploadOptions = ['folder' => 'barcodes', 'file_name' => 'barcode.png'];
$asset->save();
// Return sebagai response
return response($png, 200, ['Content-Type' => 'image/png']);File Penting
| File | Tujuan |
|---|---|
app/Services/Codegen/GenerateBarcode.php | Generate 1D barcode |
app/Services/Codegen/GenerateQRCode.php | Generate QR Code |
composer.json | Dependency milon/barcode |