59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\HasilSeleksi;
|
|
use App\Models\Kriteria;
|
|
use App\Models\Pengumuman;
|
|
use App\Models\ProfilDesa;
|
|
use Illuminate\Http\Request;
|
|
|
|
class LandingPageController extends Controller
|
|
{
|
|
// Lalu ubah fungsi index() menjadi seperti ini:
|
|
public function index()
|
|
{
|
|
$pengumumans = Pengumuman::where('status', 'aktif')->latest()->take(5)->get();
|
|
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
|
|
|
// Mengambil data profil desa (baris pertama)
|
|
$profil = ProfilDesa::first();
|
|
|
|
return view('landing-page.index', compact('pengumumans', 'kriterias', 'profil'));
|
|
}
|
|
|
|
/**
|
|
* Fitur Cek Status Bansos untuk Warga menggunakan NIK
|
|
*/
|
|
public function cekBansos(Request $request)
|
|
{
|
|
// Validasi input NIK (Harus angka dan 16 digit sesuai standar KTP)
|
|
$request->validate([
|
|
'nik' => 'required|numeric|digits:16'
|
|
], [
|
|
'nik.required' => 'Nomor NIK tidak boleh kosong.',
|
|
'nik.numeric' => 'Format NIK harus berupa angka.',
|
|
'nik.digits' => 'NIK harus berjumlah tepat 16 digit.'
|
|
]);
|
|
|
|
$nik = $request->input('nik');
|
|
|
|
// Mencari data di tabel hasil_seleksi melalui relasi ke tabel warga berdasarkan NIK
|
|
$hasil = HasilSeleksi::whereHas('warga', function ($query) use ($nik) {
|
|
$query->where('nik', $nik);
|
|
})->with(['warga', 'periode'])->latest()->first();
|
|
|
|
if ($hasil) {
|
|
// Jika ketemu, kembalikan ke landing page dengan data hasil seleksi
|
|
return redirect()->back()
|
|
->with('hasil_pencarian', $hasil)
|
|
->withFragment('cek-bansos'); // Otomatis scroll ke section cek-bansos
|
|
} else {
|
|
// Jika tidak ketemu, kirim pesan error
|
|
return redirect()->back()
|
|
->with('error_pencarian', 'Maaf, NIK ' . $nik . ' belum terdaftar atau belum masuk dalam tahap perhitungan periode ini.')
|
|
->withFragment('cek-bansos');
|
|
}
|
|
}
|
|
}
|