diff --git a/app/Http/Controllers/Web/Ekosistem/LahanCPCLController.php b/app/Http/Controllers/Web/Ekosistem/LahanCPCLController.php new file mode 100644 index 0000000..32862fd --- /dev/null +++ b/app/Http/Controllers/Web/Ekosistem/LahanCPCLController.php @@ -0,0 +1,191 @@ +orderBy('created_at', 'desc'); + + if ($request->search) { + $query->where(function($q) use ($request) { + $q->where('nama_pemilik', 'like', '%' . $request->search . '%') + ->orWhereHas('desaKelurahan', function($qDesa) use ($request) { + $qDesa->where('nama', 'like', '%' . $request->search . '%'); + }); + }); + } + if ($request->filled('status_kepemilikan')) { + $query->where('status_kepemilikan', $request->status_kepemilikan); + } + if ($request->filled('desa_kelurahan_id')) { + $query->where('desa_kelurahan_id', $request->desa_kelurahan_id); + } elseif ($request->filled('kecamatan_id')) { + $query->whereHas('desakelurahan', function($q) use ($request) { + $q->where('kecamatan_id', $request->kecamatan_id); + }); + } elseif ($request->filled('kabupatenkota_id')) { + $query->whereHas('desakelurahan.kecamatan', function($q) use ($request) { + $q->where('kabupatenkota_id', $request->kabupatenkota_id); + }); + } elseif ($request->filled('provinsi_id')) { + $query->whereHas('desakelurahan.kecamatan.kabupatenkota', function($q) use ($request) { + $q->where('provinsi_id', $request->provinsi_id); + }); + } + + $lahan = $query->paginate($request->per_page ?? 10); + + $provinsi = Provinsi::orderBy('nama', 'asc')->get(); + + $kabupaten = []; + $kecamatan = []; + $desa = []; + + if ($request->filled('provinsi_id')) { + $kabupaten = KabupatenKota::where('provinsi_id', $request->provinsi_id)->orderBy('nama', 'asc')->get(); + } + if ($request->filled('kabupatenkota_id')) { + $kecamatan = Kecamatan::where('kabupatenkota_id', $request->kabupatenkota_id)->orderBy('nama', 'asc')->get(); + } + if ($request->filled('kecamatan_id')) { + $desa = DesaKelurahan::where('kecamatan_id', $request->kecamatan_id)->orderBy('nama', 'asc')->get(); + } + + return view('ekosistem.lahan-cpcl.index', compact('lahan', 'provinsi', 'kabupaten', 'kecamatan', 'desa')); + } + + public function create() + { + $provinsi = Provinsi::orderBy('nama', 'asc')->get(); + return view('ekosistem.lahan-cpcl.add', compact('provinsi')); + } + + public function store(Request $request) + { + // dd($request->all()); + $validator = Validator::make($request->all(), [ + 'nama' => ['required', 'string', 'max:255'], + 'status_kepemilikan' => ['required', 'string', 'max:255'], + 'nama_pemilik' => ['required', 'string', 'max:255'], + 'desa_kelurahan_id' => ['nullable'], + 'luas_lahan' => ['nullable', 'numeric'], + 'path' => ['nullable', 'string'], + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'error', 'errors' => $validator->errors()], 422); + } + + $pathData = null; + + if ($request->filled('path')) { + $pathData = json_decode($request->path, true); + if (json_last_error() !== JSON_ERROR_NONE) { + return response()->json(['status' => 'error', 'message' => 'Format koordinat (path) bukan JSON array yang valid.'], 422); + } + } + + LahanCPCL::create([ + 'nama' => $request->nama, + 'status_kepemilikan' => $request->status_kepemilikan, + 'nama_pemilik' => $request->nama_pemilik, + 'desa_kelurahan_id' => $request->desa_kelurahan_id, + 'luas_lahan' => $request->luas_lahan, + 'path' => $pathData, + 'created_by' => auth()->id(), + 'updated_by' => auth()->id(), + ]); + + return response()->json(['status' => 'success', 'message' => 'Lahan berhasil ditambahkan.']); + } + + public function show($id) + { + $lahan = LahanCPCL::with(['desakelurahan.kecamatan.kabupatenkota.provinsi'])->findOrFail($id); + + return view('ekosistem.lahan-cpcl.view', compact('lahan')); + } + + public function edit($id) + { + $lahan = LahanCPCL::with('desakelurahan.kecamatan.kabupatenkota.provinsi')->findOrFail($id); + + $provinsi = Provinsi::orderBy('nama', 'asc')->get(); + + return view('ekosistem.lahan-cpcl.edit', compact('lahan', 'provinsi')); + } + + public function update(Request $request, $id) + { + $validator = Validator::make($request->all(), [ + 'nama' => ['required', 'string', 'max:255'], + 'status_kepemilikan' => ['required', 'string', 'max:255'], + 'nama_pemilik' => ['required', 'string', 'max:255'], + 'desa_kelurahan_id' => ['nullable'], + 'luas_lahan' => ['nullable', 'numeric'], + 'path' => ['nullable', 'string'], + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'error', 'errors' => $validator->errors()], 422); + } + + $lahan = LahanCPCL::findOrFail($id); + + $pathData = null; + + if ($request->filled('path')) { + $pathData = json_decode($request->path, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + return response()->json(['status' => 'error', 'message' => 'Format koordinat (path) bukan JSON array yang valid.'], 422); + } + } + + $lahan->update([ + 'nama' => $request->nama, + 'status_kepemilikan' => $request->status_kepemilikan, + 'nama_pemilik' => $request->nama_pemilik, + 'desa_kelurahan_id' => $request->desa_kelurahan_id, + 'luas_lahan' => $request->luas_lahan, + 'path' => $pathData, + 'updated_by' => auth()->id(), + ]); + + return response()->json(['status' => 'success', 'message' => 'Data Lahan berhasil diperbarui.']); + } + + public function destroy($id) + { + try { + $lahan = LahanCPCL::findOrFail($id); + + $lahan->deleted_by = auth()->id(); // atau auth()->user()->id + $lahan->save(); + + $lahan->delete(); + + return response()->json([ + 'status' => 'success', + 'message' => 'Data lahan berhasil dihapus.' + ]); + + } catch (\Exception $e) { + return response()->json([ + 'status' => 'error', + 'message' => 'Gagal menghapus data Lahan. Silakan coba lagi nanti.' + ], 500); + } + } +} diff --git a/app/Models/Ekosistem/LahanCPCL.php b/app/Models/Ekosistem/LahanCPCL.php new file mode 100644 index 0000000..f1d614f --- /dev/null +++ b/app/Models/Ekosistem/LahanCPCL.php @@ -0,0 +1,39 @@ + \App\Enums\StatusLahan::class, + 'path' => 'array', + ]; + + protected $fillable = [ + 'nama', + 'status_kepemilikan', + 'nama_pemilik', + 'desa_kelurahan_id', + 'path', + 'luas_lahan', + 'created_by', + 'updated_by', + 'deleted_by', + ]; + + public function desaKelurahan() + { + return $this->belongsTo(DesaKelurahan::class, 'desa_kelurahan_id'); + } +} diff --git a/database/migrations/2026_05_06_113516_create_ekosistem_lahan_cpcl_table.php b/database/migrations/2026_05_06_113516_create_ekosistem_lahan_cpcl_table.php new file mode 100644 index 0000000..d2d866f --- /dev/null +++ b/database/migrations/2026_05_06_113516_create_ekosistem_lahan_cpcl_table.php @@ -0,0 +1,39 @@ +id(); + $table->string('nama'); + $table->string('status_kepemilikan'); + + $table->string('nama_pemilik'); + + $table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan'); + $table->jsonb('path')->nullable(); + + $table->float('luas_lahan', 8)->nullable(); + + $table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null'); + $table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null'); + $table->foreignId('deleted_by')->nullable()->constrained('users')->onDelete('set null'); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + public function down(): void + { + Schema::dropIfExists('ekosistem_lahan_cpcl'); + } +}; diff --git a/resources/views/ekosistem/lahan-cpcl/add.blade.php b/resources/views/ekosistem/lahan-cpcl/add.blade.php new file mode 100644 index 0000000..31b1d0c --- /dev/null +++ b/resources/views/ekosistem/lahan-cpcl/add.blade.php @@ -0,0 +1,415 @@ +@extends('layout.main') + +@push('style') + + + + +@endpush + +@section('content') +
+
+
+
Tambah Data Lahan CPCL
+ + Kembali + +
+ +
+
+ @csrf + +
+
+
Form Info Lahan
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+
Lokasi Wilayah
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+ + + Pastikan menggambar polygon di peta dengan menyambungkan titik akhir ke titik awal. +
+
+ +
+
+
Gambar Area Lahan
+ Gunakan tool ⬟ di kiri peta +
+ +
+
+
+ +
+
+ + +
+
+ +
+
+
+
+@endsection + +@push('scripts') + + + +@endpush \ No newline at end of file diff --git a/resources/views/ekosistem/lahan-cpcl/edit.blade.php b/resources/views/ekosistem/lahan-cpcl/edit.blade.php new file mode 100644 index 0000000..5c751d2 --- /dev/null +++ b/resources/views/ekosistem/lahan-cpcl/edit.blade.php @@ -0,0 +1,448 @@ +@extends('layout.main') + +@push('style') + + + + +@endpush + +@section('content') +
+
+
+
Edit Data Lahan
+ + Kembali + +
+ +
+
+ @csrf + @method('PUT') + +
+
+
Form Info Lahan
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+
Lokasi Wilayah
+ + @php + $selectedDesa = $lahan->desakelurahan ?? null; + $selectedKec = $selectedDesa ? $selectedDesa->kecamatan : null; + $selectedKab = $selectedKec ? $selectedKec->kabupatenkota : null; + $selectedProv = $selectedKab ? $selectedKab->provinsi : null; + @endphp + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+ + + Gunakan tombol edit (pensil) atau hapus (tong sampah) di peta untuk mengubah bentuk lahan. +
+
+ +
+
+
Gambar Area Lahan
+ Mode Edit Polygon Aktif +
+ +
+
+
+ +
+
+ Batal + +
+
+ +
+
+
+
+@endsection + +@push('scripts') + + + +@endpush \ No newline at end of file diff --git a/resources/views/ekosistem/lahan-cpcl/index.blade.php b/resources/views/ekosistem/lahan-cpcl/index.blade.php new file mode 100644 index 0000000..7272c11 --- /dev/null +++ b/resources/views/ekosistem/lahan-cpcl/index.blade.php @@ -0,0 +1,313 @@ +@extends('layout.main') + +@push('style') + +@endpush + +@section('content') +
+
+
+
Data Map Lahan
+ +
+ + + Tambah Lahan + +
+
+ +
+ +
+
+
+
+ + + +
+
+
+
+ + + @if(request()->anyFilled(['search', 'provinsi_id', 'kabupatenkota_id', 'kecamatan_id', 'desa_kelurahan_id', 'status_kepemilikan'])) + + @endif +
+
+
+
+ + @php + $isFilterActive = request()->anyFilled([ + 'provinsi_id', 'kabupatenkota_id', 'kecamatan_id', 'desa_kelurahan_id', + 'status_kepemilikan' + ]); + @endphp + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+ +
+ +
+
+
+
+
+ +
+ + + + + + + + + + + + + + + @forelse($lahan as $index => $item) + + + + + + + + + + + @empty + + @endforelse + +
NoNama LahanPemilikStatusLokasiLuas (Ha/m2)GeoJSONActions
{{ $lahan->firstItem() + $index }}{{ $item->nama }}{{ $item->nama_pemilik ?? '-' }} + {{ ucfirst($item->status_kepemilikan->value) }} + + + @php + $kodeDesa = (string) ($item->desakelurahan->kode ?? ''); + $labelWilayah = 'Desa'; + if (strlen($kodeDesa) >= 4) { + $digitStatus = substr($kodeDesa, -4, 1); + if ($digitStatus === '1') { + $labelWilayah = 'Kel.'; + } elseif ($digitStatus === '2') { + $labelWilayah = 'Desa'; + } + } + @endphp + {{ $labelWilayah }} {{ $item->desakelurahan->nama ?? '-' }},
+ Kec. {{ $item->desakelurahan->kecamatan->nama ?? '-' }} +
+
{{ $item->luas_lahan ?? '-' }} + @if($item->path) + Ada + @else + Tidak Ada + @endif + +
+ + + +
+
Tidak ada data lahan ditemukan.
+
+ +
+
+@endsection + +@push('scripts') + + +@endpush \ No newline at end of file diff --git a/resources/views/ekosistem/lahan-cpcl/view.blade.php b/resources/views/ekosistem/lahan-cpcl/view.blade.php new file mode 100644 index 0000000..2540cc2 --- /dev/null +++ b/resources/views/ekosistem/lahan-cpcl/view.blade.php @@ -0,0 +1,223 @@ +@extends('layout.main') + +@push('style') + + + +@endpush + +@section('content') +
+
+
+
Detail Map Lahan
+ + Kembali + +
+ +
+
+ +
+
+
Info Lahan
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ + @if($lahan->status_kepemilikan->value === 'adat') +
+ + +
+ @endif + +
+
Lokasi Wilayah
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+ +
+
+
Visualisasi Peta Lahan
+ +
+ + +
+
+ +
+
+ Memuat Peta... +
+
+ +
+ + +
+
+
+ +
+
+
+
+ + +@endsection + +@push('scripts') + +@endpush \ No newline at end of file