Data master keluarga

This commit is contained in:
2026-05-06 11:44:37 +07:00
parent 8416e92e17
commit 2dd13aa873
2 changed files with 43 additions and 43 deletions
@@ -13,6 +13,12 @@ class KeluargaController extends Controller
{ {
public function index(Request $request) public function index(Request $request)
{ {
// 1. Ambil data dinamis untuk Summary Cards
$totalKeluarga = Keluarga::count();
$dokumenLengkap = Keluarga::whereNotNull('file_kk')->count();
$totalDesa = Keluarga::distinct('desa_kelurahan_id')->count('desa_kelurahan_id');
// 2. Query bawaan untuk tabel
$query = Keluarga::with(['desakelurahan', 'adat'])->orderBy('created_at', 'desc'); $query = Keluarga::with(['desakelurahan', 'adat'])->orderBy('created_at', 'desc');
if ($request->search) { if ($request->search) {
@@ -20,48 +26,9 @@ class KeluargaController extends Controller
} }
$keluarga = $query->paginate($request->per_page ?? 10); $keluarga = $query->paginate($request->per_page ?? 10);
return view('master.keluarga.index', compact('keluarga'));
} // 3. Tambahkan variabel card ke dalam compact()
return view('master.keluarga.index', compact('keluarga', 'totalKeluarga', 'dokumenLengkap', 'totalDesa'));
public function create()
{
$provinsi = Provinsi::orderBy('nama', 'asc')->get();
return view('master.keluarga.add', compact('provinsi'));
}
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'kk' => ['required', 'string', 'min:16', 'max:16'],
'desa_kelurahan_id' => ['required'],
'adat_id' => ['nullable'],
'file_kk' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'],
]);
if ($validator->fails()) {
return response()->json(['status' => 'error', 'errors' => $validator->errors()], 422);
}
$pathKk = null;
$fileNameKk = null;
if ($request->hasFile('file_kk')) {
$file = $request->file('file_kk');
$fileNameKk = $file->getClientOriginalName();
$pathKk = $file->store('uploads/keluarga', 'public');
}
Keluarga::create([
'kk' => $request->kk,
'desa_kelurahan_id' => $request->desa_kelurahan_id,
'adat_id' => $request->adat_id,
'path_kk' => $pathKk,
'file_kk' => $fileNameKk,
'created_by' => auth()->id(),
'updated_by' => auth()->id(),
]);
return response()->json(['status' => 'success', 'message' => 'Data Keluarga berhasil ditambahkan.']);
} }
public function show($id) public function show($id)
@@ -1,7 +1,40 @@
@extends('layout.main') @extends('layout.main')
@section('content') @section('content')
<div class="container-xxl flex-grow-1 container-p-y"> <div class="container-xxl flex-grow-3 container-p-y">
<div class="row g-4 mb-6">
<div class="col-md-4">
<x-summary-card
title="Total Keluarga"
count="{{ $totalKeluarga }}"
subtitle="Keseluruhan KK terdaftar"
icon="users"
color="primary"
/>
</div>
<div class="col-md-4">
<x-summary-card
title="Dokumen Lengkap"
count="{{ $dokumenLengkap }}"
subtitle="File KK telah diunggah"
icon="file-check"
color="warning"
/>
</div>
<div class="col-md-4">
<x-summary-card
title="Total Desa/Kelurahan"
count="{{ $totalDesa }}"
subtitle="Cakupan wilayah"
icon="map-pin"
color="danger"
/>
</div>
</div>
<div class="card"> <div class="card">
<div class="card-header border-bottom"> <div class="card-header border-bottom">
<h5 class="card-title mb-0">Data Master Keluarga</h5> <h5 class="card-title mb-0">Data Master Keluarga</h5>