<?php

namespace App\Http\Controllers\calonsiswa;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Illuminate\Http\Request;
use PDF;
use App\Models\Pendaftar;
use App\Models\Periodik;
use App\Models\AsalSekolah;
use App\Models\Prestasi;
use App\Models\OrangTua;
use Auth;

class PDFController extends Controller
{
    public function index(Request $req)
    {
      $this->data['kartu'] = Auth::user()->pendaftar;
      $id = Auth::user()->pendaftar->id;
      $this->data['periodik'] = Periodik::where('id_pendaftar',$id)->first();
      $this->data['smp'] = AsalSekolah::where('id_pendaftar',$id)->first();
      $this->data['ot'] = OrangTua::where('id_pendaftar',$id)->first();
      $this->data['pres'] = Prestasi::where('id_pendaftar',$id)->first();
      return view('calonsiswa.pdf.index',$this->data);
    }


    public function getPDF(Request $request)
    {
      $id = Auth::user()->id;
      
      $kartu = Pendaftar::where('user_id','=',$id)->get();
      view()->share('pendaftar',$kartu);
      $pdf = PDF::loadView('calonsiswa.pdf.kartu');
      return $pdf->download('kartu.pdf');
    }
}
