Update seeder sesuai dengan data asli

This commit is contained in:
daffarahman11 2025-03-24 23:48:53 +07:00
parent 9e5026d18f
commit 0926843fc9
4 changed files with 161 additions and 83 deletions

View File

@ -74,6 +74,14 @@ public function update(Request $request, Curanmor $curanmor)
*/ */
public function destroy(Curanmor $curanmor) public function destroy(Curanmor $curanmor)
{ {
// try{
$hapus = Curanmor::find($curanmor);
Curanmor::destroy($hapus);
return redirect('/curanmor')->with('succes', 'Data Curanmor Berhasil Di Hapus');
}catch (\Exception $e){
return redirect('/curanmor')->with('error', 'Data Curanmor '. $curanmor->nama_kecamatan .' Gagal Di Hapus');
}
} }
} }

View File

@ -15,45 +15,44 @@ class CuranmorSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
$klasterId = Klaster::pluck('id'); $klasterIds = Klaster::pluck('id'); // Ambil semua ID klaster
$kecamatanId1 = Kecamatan::where('id', '1')->first(); $kecamatanIds = Kecamatan::pluck('id'); // Ambil semua ID kecamatan
$kecamatanId2 = Kecamatan::where('id', '2')->first();
$kecamatanId3 = Kecamatan::where('id', '3')->first();
$kecamatanId4 = Kecamatan::where('id', '4')->first();
$kecamatanId5 = Kecamatan::where('id', '5')->first();
$kecamatanId6 = Kecamatan::where('id', '6')->first();
// Data jumlah curanmor untuk setiap kecamatan
// Buat data kecamatan dengan klaster_id yang valid $dataCuranmor= [
Curanmor::create([ 1 => 5,
'kecamatan_id' => $kecamatanId1->id, 2 => 4,
'jumlah_curanmor' => 90, 3 => 2,
'klaster_id' => $klasterId->random(),// Ambil klaster secara acak 4 => 22,
]); 5 => 4,
Curanmor::create([ 6 => 18,
'kecamatan_id' => $kecamatanId2->id, 7 => 0,
'jumlah_curanmor' => 76, 8 => 37,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 9 => 9,
]); 10 => 3,
Curanmor::create([ 11 => 2,
'kecamatan_id' => $kecamatanId3->id, 12 => 13,
'jumlah_curanmor' => 23, 13 => 1,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 14 => 21,
]); 15 => 14,
Curanmor::create([ 16 => 4,
'kecamatan_id' => $kecamatanId4->id, 17 => 10,
'jumlah_curanmor' => 87, 18 => 0,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 19 => 1,
]); 20 => 10,
Curanmor::create([ 21 => 1,
'kecamatan_id' => $kecamatanId5->id, 22 => 2,
'jumlah_curanmor' => 56, 23 => 15,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 24 => 4,
]); ];
Curanmor::create([
'kecamatan_id' => $kecamatanId6->id, // Looping untuk membuat data curanmor berdasarkan kecamatan
'jumlah_curanmor' => 54, foreach ($kecamatanIds as $kecamatanId) {
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak Curanmor::create([
]); 'kecamatan_id' => $kecamatanId,
'jumlah_curanmor' => $dataCuranmor[$kecamatanId], // Gunakan nilai default jika tidak ada data
'klaster_id' => $klasterIds->random(), // Pilih klaster secara acak
]);
}
} }
} }

View File

@ -15,45 +15,44 @@ class CurasSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
$klasterId = Klaster::pluck('id'); $klasterIds = Klaster::pluck('id'); // Ambil semua ID klaster
$kecamatanId1 = Kecamatan::where('id', '1')->first(); $kecamatanIds = Kecamatan::pluck('id'); // Ambil semua ID kecamatan
$kecamatanId2 = Kecamatan::where('id', '2')->first();
$kecamatanId3 = Kecamatan::where('id', '3')->first();
$kecamatanId4 = Kecamatan::where('id', '4')->first();
$kecamatanId5 = Kecamatan::where('id', '5')->first();
$kecamatanId6 = Kecamatan::where('id', '6')->first();
// Data jumlah curas untuk setiap kecamatan (sesuaikan dengan kebutuhan)
// Buat data kecamatan dengan klaster_id yang valid $dataCuras = [
Curas::create([ 1 => 0,
'kecamatan_id' => $kecamatanId1->id, 2 => 0,
'jumlah_curas' => 32, 3 => 0,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 4 => 0,
]); 5 => 1,
Curas::create([ 6 => 1,
'kecamatan_id' => $kecamatanId2->id, 7 => 0,
'jumlah_curas' => 77, 8 => 0,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 9 => 0,
]); 10 => 0,
Curas::create([ 11 => 0,
'kecamatan_id' => $kecamatanId3->id, 12 => 0,
'jumlah_curas' => 44, 13 => 0,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 14 => 0,
]); 15 => 0,
Curas::create([ 16 => 0,
'kecamatan_id' => $kecamatanId4->id, 17 => 0,
'jumlah_curas' => 5, 18 => 0,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 19 => 0,
]); 20 => 1,
Curas::create([ 21 => 0,
'kecamatan_id' => $kecamatanId5->id, 22 => 0,
'jumlah_curas' => 55, 23 => 1,
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak 24 => 0,
]); ];
Curas::create([
'kecamatan_id' => $kecamatanId6->id, // Looping untuk membuat data curas berdasarkan kecamatan
'jumlah_curas' => 43, foreach ($kecamatanIds as $kecamatanId) {
'klaster_id' => $klasterId->random(), // Ambil klaster secara acak Curas::create([
]); 'kecamatan_id' => $kecamatanId,
'jumlah_curas' => $dataCuras[$kecamatanId], // Gunakan nilai default jika tidak ada data
'klaster_id' => $klasterIds->random(), // Pilih klaster secara acak
]);
}
} }
} }

View File

@ -14,11 +14,15 @@ class KecamatanSeeder extends Seeder
public function run(): void public function run(): void
{ {
Kecamatan::create([ Kecamatan::create([
'nama_kecamatan'=> 'Leces', 'nama_kecamatan'=> 'Bantaran',
]); ]);
Kecamatan::create([ Kecamatan::create([
'nama_kecamatan'=> 'Tegalsiwalan', 'nama_kecamatan'=> 'Banyuanyar',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Besuk',
]); ]);
Kecamatan::create([ Kecamatan::create([
@ -26,7 +30,7 @@ public function run(): void
]); ]);
Kecamatan::create([ Kecamatan::create([
'nama_kecamatan'=> 'Kraksaan', 'nama_kecamatan'=> 'Gading',
]); ]);
Kecamatan::create([ Kecamatan::create([
@ -34,7 +38,75 @@ public function run(): void
]); ]);
Kecamatan::create([ Kecamatan::create([
'nama_kecamatan'=> 'Gading', 'nama_kecamatan'=> 'Kotaanyar',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Kraksaan',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Krenjengan',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Krucil',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Kuripan',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Leces',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Lumbang',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Maron',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Paiton',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Pakuniran',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Pajarakan',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Sukapura',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Sumber',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Sumberasih',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Tegalsiwalan',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Tiris',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Tongas',
]);
Kecamatan::create([
'nama_kecamatan'=> 'Wonomerto',
]); ]);
} }
} }