57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\HasilPengujian;
|
|
use Illuminate\Http\Request;
|
|
use App\Exports\PrediksiExport;
|
|
use App\Models\DataUji;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
class PrediksiController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$search = $request->input('search');
|
|
|
|
// Cek apakah ada data hasil pengujian
|
|
$hasilQuery = HasilPengujian::query();
|
|
if ($search) {
|
|
$hasilQuery->where('kecamatan', 'like', "%{$search}%");
|
|
}
|
|
$hasilCount = $hasilQuery->count();
|
|
|
|
if ($hasilCount > 0) {
|
|
// Ambil dari hasil pengujian
|
|
$dataPrediksi = $hasilQuery->paginate(10)->withQueryString();
|
|
} else {
|
|
// Jika kosong, ambil dari data uji
|
|
$ujiQuery = DataUji::query();
|
|
if ($search) {
|
|
$ujiQuery->where('kecamatan', 'like', "%{$search}%");
|
|
}
|
|
$dataPrediksi = $ujiQuery->paginate(10)->withQueryString();
|
|
}
|
|
|
|
return view('admin.prediksi.index', compact('dataPrediksi'));
|
|
}
|
|
|
|
// Export ke Excel
|
|
public function exportExcel()
|
|
{
|
|
return Excel::download(new PrediksiExport, 'prediksi-ispa.xlsx');
|
|
}
|
|
|
|
// Tampilkan semua prediksi (tanpa filter)
|
|
public function showPrediksi()
|
|
{
|
|
$dataPrediksi = HasilPengujian::all();
|
|
return view('admin.prediksi', compact('dataPrediksi'));
|
|
}
|
|
public function kecamatanRel()
|
|
{
|
|
return $this->belongsTo(Kecamatan::class, 'id_kecamatan');
|
|
}
|
|
|
|
}
|