where('is_active', true)->firstOrFail(); $program = $qrCode->program; abort_if($program->status !== 'published', 404); return view('public.semak.show', compact('program', 'qrCode')); } public function check(string $qr_token, Request $request): View { $qrCode = ProgramQrCode::where('token', $qr_token)->where('is_active', true)->firstOrFail(); $program = $qrCode->program; $request->validate([ 'no_kp' => ['required', 'digits:12'], ], [ 'no_kp.required' => 'Sila masukkan No. Kad Pengenalan anda.', 'no_kp.digits' => 'No. Kad Pengenalan mestilah 12 digit tanpa sempang.', ]); $noKp = preg_replace('/[^0-9]/', '', $request->no_kp); $participant = Participant::where('no_kp', $noKp)->first(); if (! $participant) { return view('public.semak.result', [ 'program' => $program, 'qrCode' => $qrCode, 'found' => false, 'participant' => null, 'attendance' => null, 'certificate' => null, ]); } $attendance = $participant->attendanceForProgram($program->id); $certificate = $attendance ? Certificate::where('program_id', $program->id) ->where('participant_id', $participant->id) ->first() : null; return view('public.semak.result', compact('program', 'qrCode', 'participant', 'attendance', 'certificate')) ->with('found', (bool) $attendance); } }