<?php

namespace App\Http\Controllers\PDF;

use Carbon\Carbon;
use App\Models\Student;
use Barryvdh\DomPDF\Facade\Pdf;
use App\Http\Controllers\Controller;

class StudentGrowthController extends Controller
{
    public function generate(Student $student)
    {
        $growths = $student->growths()->with('user')->get();

        Carbon::setLocale('id');
        $tanggal = Carbon::now()->translatedFormat('d F Y');

        $pdf = Pdf::loadView('PDF.student-growth', [
            'student' => $student,
            'growths' => $growths,
        ])->setPaper('A4', 'portrait');

        return $pdf->download("LAPORAN_PERKEMBANGAN_SISWA_{$student->name}_{$tanggal}.pdf");
    }
}
