when(auth()->user()->isScopedWaliKelas(), fn ($q) => $q->whereHas('student', fn ($qq) => $qq->whereIn('class_id', auth()->user()->homeroomClassIds()))) ->latest() ->paginate(20); return view('sp-letters.index', compact('letters')); } public function show(SpLetter $spLetter): View { abort_unless(auth()->user()->canViewStudent($spLetter->student_id), 403); $spLetter->load(['student', 'spThreshold', 'generator']); $school = [ 'name' => Setting::getValue('school_name', 'SMK'), 'address' => Setting::getValue('school_address', ''), 'phone' => Setting::getValue('school_phone', ''), 'kepala_sekolah' => Setting::getValue('kepala_sekolah_name', ''), 'kepala_sekolah_nip' => Setting::getValue('kepala_sekolah_nip', ''), ]; return view('sp-letters.show', compact('spLetter', 'school')); } public function print(SpLetter $spLetter) { abort_unless(auth()->user()->canViewStudent($spLetter->student_id), 403); $spLetter->load(['student', 'spThreshold', 'generator']); $school = [ 'name' => Setting::getValue('school_name', 'SMK'), 'address' => Setting::getValue('school_address', ''), 'phone' => Setting::getValue('school_phone', ''), 'kepala_sekolah' => Setting::getValue('kepala_sekolah_name', ''), 'kepala_sekolah_nip' => Setting::getValue('kepala_sekolah_nip', ''), ]; $spLetter->update(['printed_at' => now(), 'status' => 'printed']); // For now, return an HTML print view return view('sp-letters.print', compact('spLetter', 'school')); } }