<?php

namespace App\Http\Controllers\PDF;

use Carbon\Carbon;
use App\Models\StudentTask;
use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade\Pdf;
use App\Http\Controllers\Controller;

class StudentGradeController extends Controller
{
    public function generate($task)
    {
        $task = StudentTask::with(['nilai.student', 'classroom'])->findOrFail($task);
    
        Carbon::setLocale('id');
        $tanggal = Carbon::now()->translatedFormat('d F Y');
    
        return Pdf::loadView('PDF.student-grade', [
            'task' => $task,
            'grades' => $task->nilai,
        ])->download('REKAP_NILAI_' . $task->name . '_' . $tanggal . '.pdf');
    }    
}
