fix(master-land): optimize func store

This commit is contained in:
arieeefajar 2025-06-13 22:41:33 +07:00
parent 6b1f43e7d7
commit 589e3189a2
10 changed files with 8 additions and 4537 deletions

View File

@ -20,27 +20,16 @@ public function index()
public function create() public function create()
{ {
$provinces = Province::all(); return view('master-data.lahan.create');
return view('master-data.lahan.create', compact('provinces'));
} }
public function store(Request $request) public function store(Request $request)
{ {
dd($request->all());
$customMessage = [ $customMessage = [
'owner.required' => 'Nama pemilik wajib diisi', 'owner.required' => 'Nama pemilik wajib diisi',
'owner.max' => 'Nama pemilik maksimal 25 karakter', 'owner.max' => 'Nama pemilik maksimal 25 karakter',
'owner.string' => 'Nama pemilik harus berupa string', 'owner.string' => 'Nama pemilik harus berupa string',
'province_id.required' => 'Provinsi wajib diisi',
'province_id.exists' => 'Provinsi tidak ditemukan',
'regency_id.required' => 'Kota wajib diisi',
'regency_id.exists' => 'Kota tidak ditemukan',
'district_id.required' => 'Kecamatan wajib diisi',
'district_id.exists' => 'Kecamatan tidak ditemukan',
'address.required' => 'Alamat wajib diisi', 'address.required' => 'Alamat wajib diisi',
'address.max' => 'Alamat maksimal 100 karakter', 'address.max' => 'Alamat maksimal 100 karakter',
'address.string' => 'Alamat harus berupa string', 'address.string' => 'Alamat harus berupa string',
@ -56,9 +45,6 @@ public function store(Request $request)
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'owner' => 'required|string|max:25', 'owner' => 'required|string|max:25',
'province_id' => 'required|exists:provinces,id',
'regency_id' => 'required|exists:regencies,id',
'district_id' => 'required|exists:districts,id',
'address' => 'required|string|max:100', 'address' => 'required|string|max:100',
'lat' => 'required|numeric', 'lat' => 'required|numeric',
'lng' => 'required|numeric', 'lng' => 'required|numeric',
@ -77,12 +63,7 @@ public function store(Request $request)
$land = new Land(); $land = new Land();
$land->user_id = Auth::user()->id; $land->user_id = Auth::user()->id;
$land->owner = $request->owner; $land->owner = $request->owner;
$land->province_code = $request->province_id;
$land->regency_code = $request->regency_id;
$land->district_code = $request->district_id;
$land->address = $request->address; $land->address = $request->address;
$land->latitude = $request->lat;
$land->longitude = $request->lng;
$land->save(); $land->save();
foreach ($polygon as $point) { foreach ($polygon as $point) {

View File

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('provinces', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('alt_name');
$table->double('latitude');
$table->double('longitude');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('provinces');
}
};

View File

@ -1,36 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('regencies', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('province_id');
$table->string('name');
$table->string('alt_name');
$table->double('latitude');
$table->double('longitude');
$table->timestamps();
});
Schema::table('regencies', function (Blueprint $table) {
$table->foreign('province_id')->references('id')->on('provinces');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('regencies');
}
};

View File

@ -1,36 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('districts', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('regency_id');
$table->string('name');
$table->string('alt_name');
$table->double('latitude');
$table->double('longitude');
$table->timestamps();
});
Schema::table('districts', function (Blueprint $table) {
$table->foreign('regency_id')->references('id')->on('regencies');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('districts');
}
};

View File

@ -15,12 +15,7 @@ public function up(): void
$table->id(); $table->id();
$table->unsignedBigInteger('user_id'); $table->unsignedBigInteger('user_id');
$table->string('owner'); $table->string('owner');
$table->string('province_code');
$table->string('regency_code');
$table->string('district_code');
$table->string('address'); $table->string('address');
$table->string('latitude');
$table->string('longitude');
$table->timestamps(); $table->timestamps();
}); });

View File

@ -22,9 +22,6 @@ public function run(): void
$this->call([ $this->call([
UsersSeeder::class, UsersSeeder::class,
ProvinceSeeder::class,
RegenciesSeeder::class,
// LandSeeder::class,
IndicatorSeeder::class, IndicatorSeeder::class,
RuleSeeder::class, RuleSeeder::class,
RuleExpertSeeder::class RuleExpertSeeder::class

View File

@ -1,261 +0,0 @@
<?php
namespace Database\Seeders;
use App\Models\Province;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class ProvinceSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$provinces = [
[
'id' => 11,
'name' => 'ACEH',
'alt_name' => 'ACEH',
'latitude' => 4.368550,
'longitude' => 97.025300,
],
[
'id' => 12,
'name' => 'SUMATERA UTARA',
'alt_name' => 'SUMATERA UTARA',
'latitude' => 2.192350,
'longitude' => 99.381220,
],
[
'id' => 13,
'name' => 'SUMATERA BARAT',
'alt_name' => 'SUMATERA BARAT',
'latitude' => -1.342250,
'longitude' => 100.076100,
],
[
'id' => 14,
'name' => 'RIAU',
'alt_name' => 'RIAU',
'latitude' => 0.500410,
'longitude' => 101.547580,
],
[
'id' => 15,
'name' => 'JAMBI',
'alt_name' => 'JAMBI',
'latitude' => -1.611570,
'longitude' => 102.779700,
],
[
'id' => 16,
'name' => 'SUMATERA SELATAN',
'alt_name' => 'SUMATERA SELATAN',
'latitude' => -3.126680,
'longitude' => 104.093060,
],
[
'id' => 17,
'name' => 'BENGKULU',
'alt_name' => 'BENGKULU',
'latitude' => -3.518680,
'longitude' => 102.535980,
],
[
'id' => 18,
'name' => 'LAMPUNG',
'alt_name' => 'LAMPUNG',
'latitude' => -4.855500,
'longitude' => 105.027300,
],
[
'id' => 19,
'name' => 'KEPULAUAN BANGKA BELITUNG',
'alt_name' => 'KEPULAUAN BANGKA BELITUNG',
'latitude' => -2.757750,
'longitude' => 107.583940,
],
[
'id' => 21,
'name' => 'KEPULAUAN RIAU',
'alt_name' => 'KEPULAUAN RIAU',
'latitude' => -0.154780,
'longitude' => 104.580370,
],
[
'id' => 31,
'name' => 'DKI JAKARTA',
'alt_name' => 'DKI JAKARTA',
'latitude' => 6.174500,
'longitude' => 106.822700,
],
[
'id' => 32,
'name' => 'JAWA BARAT',
'alt_name' => 'JAWA BARAT',
'latitude' => -6.889170,
'longitude' => 107.640470,
],
[
'id' => 33,
'name' => 'JAWA TENGAH',
'alt_name' => 'JAWA TENGAH',
'latitude' => -7.303240,
'longitude' => 110.004410,
],
[
'id' => 34,
'name' => 'DI YOGYAKARTA',
'alt_name' => 'DI YOGYAKARTA',
'latitude' => 7.795600,
'longitude' => 110.369500,
],
[
'id' => 35,
'name' => 'JAWA TIMUR',
'alt_name' => 'JAWA TIMUR',
'latitude' => -6.968510,
'longitude' => 113.980050,
],
[
'id' => 36,
'name' => 'BANTEN',
'alt_name' => 'BANTEN',
'latitude' => -6.445380,
'longitude' => 106.137560,
],
[
'id' => 51,
'name' => 'BALI',
'alt_name' => 'BALI',
'latitude' => -8.235660,
'longitude' => 115.122390,
],
[
'id' => 52,
'name' => 'NUSA TENGGARA BARAT',
'alt_name' => 'NUSA TENGGARA BARAT',
'latitude' => -8.121790,
'longitude' => 117.636960,
],
[
'id' => 53,
'name' => 'NUSA TENGGARA TIMUR',
'alt_name' => 'NUSA TENGGARA TIMUR',
'latitude' => -8.565680,
'longitude' => 120.697860,
],
[
'id' => 61,
'name' => 'KALIMANTAN BARAT',
'alt_name' => 'KALIMANTAN BARAT',
'latitude' => -0.132240,
'longitude' => 111.096890,
],
[
'id' => 62,
'name' => 'KALIMANTAN TENGAH',
'alt_name' => 'KALIMANTAN TENGAH',
'latitude' => -1.499580,
'longitude' => 113.290330,
],
[
'id' => 63,
'name' => 'KALIMANTAN SELATAN',
'alt_name' => 'KALIMANTAN SELATAN',
'latitude' => -2.943480,
'longitude' => 115.375650,
],
[
'id' => 64,
'name' => 'KALIMANTAN TIMUR',
'alt_name' => 'KALIMANTAN TIMUR',
'latitude' => 0.788440,
'longitude' => 116.242000,
],
[
'id' => 65,
'name' => 'KALIMANTAN UTARA',
'alt_name' => 'KALIMANTAN UTARA',
'latitude' => 2.725940,
'longitude' => 116.911000,
],
[
'id' => 71,
'name' => 'SULAWESI UTARA',
'alt_name' => 'SULAWESI UTARA',
'latitude' => 0.655570,
'longitude' => 124.090150,
],
[
'id' => 72,
'name' => 'SULAWESI TENGAH',
'alt_name' => 'SULAWESI TENGAH',
'latitude' => -1.693780,
'longitude' => 120.808860,
],
[
'id' => 73,
'name' => 'SULAWESI SELATAN',
'alt_name' => 'SULAWESI SELATAN',
'latitude' => -3.644670,
'longitude' => 119.947190,
],
[
'id' => 74,
'name' => 'SULAWESI TENGGARA',
'alt_name' => 'SULAWESI TENGGARA',
'latitude' => -3.549120,
'longitude' => 121.727960,
],
[
'id' => 75,
'name' => 'GORONTALO',
'alt_name' => 'GORONTALO',
'latitude' => 0.718620,
'longitude' => 122.455590,
],
[
'id' => 76,
'name' => 'SULAWESI BARAT',
'alt_name' => 'SULAWESI BARAT',
'latitude' => -2.497450,
'longitude' => 119.391900,
],
[
'id' => 81,
'name' => 'MALUKU',
'alt_name' => 'MALUKU',
'latitude' => -3.118840,
'longitude' => 129.420780,
],
[
'id' => 82,
'name' => 'MALUKU UTARA',
'alt_name' => 'MALUKU UTARA',
'latitude' => 0.630120,
'longitude' => 127.972020,
],
[
'id' => 91,
'name' => 'PAPUA BARAT',
'alt_name' => 'PAPUA BARAT',
'latitude' => -1.384240,
'longitude' => 132.902530,
],
[
'id' => 94,
'name' => 'PAPUA',
'alt_name' => 'PAPUA',
'latitude' => -3.988570,
'longitude' => 138.348530,
],
];
foreach ($provinces as $province) {
Province::create($province);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,10 @@ var polygonField = form.querySelector("#polygon");
var loading = form.querySelector("#loading"); var loading = form.querySelector("#loading");
var btnContainer = form.querySelector("#add-footer"); var btnContainer = form.querySelector("#add-footer");
document.addEventListener("DOMContentLoaded", function () {
initMap();
});
function initMap() { function initMap() {
map = L.map("map", { map = L.map("map", {
attributionControl: false, attributionControl: false,
@ -156,10 +160,6 @@ function getLocation() {
); );
} }
document.addEventListener("DOMContentLoaded", function () {
initMap();
});
async function onPointerDragend() { async function onPointerDragend() {
if (!currentMarker) return; if (!currentMarker) return;
var coordinates = currentMarker.getLatLng(); var coordinates = currentMarker.getLatLng();
@ -172,7 +172,9 @@ async function onPointerDragend() {
addressContainer.style.display = "block"; addressContainer.style.display = "block";
addressField.value = address; addressField.value = address;
} catch (error) { } catch (error) {
alert(`Error ` + error.message);
} finally { } finally {
loading.style.display = "none";
} }
currentMarker currentMarker
@ -190,7 +192,6 @@ function handleDrawCreated(e) {
var layer = e.layer; var layer = e.layer;
drawnItems.addLayer(layer); drawnItems.addLayer(layer);
var coordinates = layer.getLatLngs()[0]; var coordinates = layer.getLatLngs()[0];
console.log("Koordinat Polygon:", coordinates);
polygonField.value = JSON.stringify(coordinates); polygonField.value = JSON.stringify(coordinates);
layer.bindPopup("<b>Petak Lahan Berhasil Dibuat!</b>").openPopup(); layer.bindPopup("<b>Petak Lahan Berhasil Dibuat!</b>").openPopup();
@ -201,7 +202,6 @@ function handleDrawEdited(e) {
var layers = e.layers; var layers = e.layers;
layers.eachLayer(function (layer) { layers.eachLayer(function (layer) {
var coordinates = layer.getLatLngs(); var coordinates = layer.getLatLngs();
console.log("Koordinat setelah diedit:", coordinates);
polygonField.value = JSON.stringify(coordinates); polygonField.value = JSON.stringify(coordinates);
layer.bindPopup("<b>Petak Lahan Berhasil Diedit!</b>").openPopup(); layer.bindPopup("<b>Petak Lahan Berhasil Diedit!</b>").openPopup();

View File

@ -64,10 +64,7 @@ class="fw-medium link-primary">#VZ2101</a></td>
<td class="owner">{{ $land->owner }}</td> <td class="owner">{{ $land->owner }}</td>
</td> </td>
<td class="status"> <td class="status">
<span class="text-capitalize">{{ $land->address }}, Kecamatan <span class="text-capitalize">{{ $land->address }}</span>
{{ ucwords(strtolower($land->district->name)) }},
{{ ucwords(strtolower($land->regency->name)) }}, Provinsi
{{ ucwords(strtolower($land->province->name)) }}</span>
</td> </td>
@if (Auth::user()->role == 'admin') @if (Auth::user()->role == 'admin')
<td class="user">{{ $land->user->username }}</td> <td class="user">{{ $land->user->username }}</td>