56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\RiwayatDiagnosa;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
|
|
class RiwayatController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$user = Auth::user();
|
|
|
|
$riwayat = RiwayatDiagnosa::with([
|
|
'detail.penyakit'
|
|
])
|
|
->where('user_id', $user->id)
|
|
->orderBy('created_at', 'desc')
|
|
->get();
|
|
|
|
return view('auth.riwayat', compact('riwayat'));
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$riwayat = RiwayatDiagnosa::with([
|
|
'detail.penyakit',
|
|
'detail.gejala'
|
|
])->findOrFail($id);
|
|
|
|
if ($riwayat->user_id !== Auth::id()) {
|
|
abort(403, 'Akses tidak diizinkan.');
|
|
}
|
|
|
|
return view('auth.riwayat_pdf', compact('riwayat'));
|
|
}
|
|
|
|
public function cetakPdf($id)
|
|
{
|
|
$riwayat = RiwayatDiagnosa::with([
|
|
'detail.penyakit.solusi',
|
|
'detail.gejala'
|
|
])->findOrFail($id);
|
|
|
|
if ($riwayat->user_id !== Auth::id()) {
|
|
abort(403, 'Akses tidak diizinkan.');
|
|
}
|
|
|
|
$pdf = PDF::loadView('auth.cetakpdf', compact('riwayat'))
|
|
->setPaper('A4', 'portrait');
|
|
|
|
return $pdf->download('diagnosa-' . $riwayat->id . '.pdf');
|
|
}
|
|
}
|