<?php
namespace App\Http\Controllers\Peserta;
use App\Facades\DataTable;
use App\Http\Controllers\Controller;
use App\Models\PelatihanPeserta;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Barryvdh\DomPDF\Facade\Pdf;
class SertifikatController extends Controller
{
public function index(){
$sort = str_replace(
['created_at'],
[ 'created_at'],
request()->query('col')
);
$result = DataTable::query(PelatihanPeserta::has('user')->with('pelatihan')->where('user_id',auth()->user()->id)->where('status','approve')->has('pelatihan'))
->with(['user.peserta','pelatihan'])
->searchable(['pelatihan.title','pelatihan.description','user.nama', 'user.email','user.peserta.nik'])
->applySort($sort)
->allowedSorts(['created_at'])
->make()->toArray();
return Inertia::render('Peserta/Sertifikat/Index',[
'datatable'=>$result,
]);
}
public function print($id){
$pelatihanPeserta = PelatihanPeserta::has('user.peserta')->with('user.peserta','pelatihan','jawaban_syarat_pelatihans.syarat_pelatihan','user.peserta.provinsi','user.peserta.kabupaten')->findOrFail($id);
if($pelatihanPeserta->status !== "finish"){
return abort(404);
}
$pelatihanPeserta = PelatihanPeserta::with('user.peserta', 'pelatihan.pelatihan_materis', 'jawaban_syarat_pelatihans.syarat_pelatihan', 'user.peserta.provinsi', 'user.peserta.kabupaten')->findOrFail($id);
$noSertifikat = ($pelatihanPeserta->id+170).'GN-'.date("m/Y",strtotime($pelatihanPeserta->pelatihan->end_date));
//return view('sertifikat',compact('pelatihanPeserta','noSertifikat'));
$pdf = Pdf::loadView('sertifikat', compact('pelatihanPeserta','noSertifikat'));
$pdf->setPaper('A4', 'landscape');
// $pdf->setOption(['isRemoteEnabled' => true]);
return $pdf->stream('sertifikat.pdf');
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]