Files
eCert-MBIP/app/Services/QrCodeService.php
Saufi 756b73e3ee fix: QR code guna Storage::disk('public') — imej tidak papar di admin panel
Storage::put() guna default disk (local/private) menyebabkan fail disimpan
di storage/app/private/public/qrcodes/ tapi URL /storage/qrcodes/... cari
fail di storage/app/public/qrcodes/ melalui symlink — lokasi berbeza.

- QrCodeService: guna disk('public'), path ringkas 'qrcodes/{token}.png'
- View: Storage::disk('public')->url() untuk URL yang betul

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 20:37:42 +08:00

48 lines
1.3 KiB
PHP

<?php
namespace App\Services;
use App\Models\Program;
use App\Models\ProgramQrCode;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
class QrCodeService
{
public function generateForProgram(Program $program): ProgramQrCode
{
$program->qrCodes()->where('is_active', true)->update(['is_active' => false]);
$token = Str::random(48);
$url = route('public.checkin.show', $token);
$path = 'qrcodes/' . $token . '.png';
Storage::disk('public')->makeDirectory('qrcodes');
$png = QrCode::format('png')
->size(400)
->margin(2)
->errorCorrection('H')
->generate($url);
Storage::disk('public')->put($path, $png);
return $program->qrCodes()->create([
'token' => $token,
'qr_image_path' => $path,
'is_active' => true,
]);
}
public function getPublicUrl(ProgramQrCode $qrCode): string
{
return Storage::disk('public')->url($qrCode->qr_image_path);
}
public function getRawPng(ProgramQrCode $qrCode): string
{
return Storage::disk('public')->get($qrCode->qr_image_path);
}
}