85 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			85 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| 
 | |
| namespace Database\Seeders;
 | |
| 
 | |
| use Illuminate\Database\Seeder;
 | |
| use App\Models\Perusahaan;
 | |
| use App\Models\Kelurahan;
 | |
| use Faker\Factory as Faker;
 | |
| 
 | |
| class PerusahaanSeeder extends Seeder
 | |
| {
 | |
|     /**
 | |
|      * Run the database seeds.
 | |
|      */
 | |
|     public function run(): void
 | |
|     {
 | |
|         $faker = Faker::create('id_ID');
 | |
| 
 | |
|         $data = [];
 | |
|         $timestamp = now();
 | |
| 
 | |
|         // Get available Kelurahan IDs from the database
 | |
|         $kelurahanIds = Kelurahan::pluck('KelurahanId')->toArray();
 | |
| 
 | |
|         // Make sure we have Kelurahan records
 | |
|         if (empty($kelurahanIds)) {
 | |
|             throw new \Exception("No Kelurahan records found. Please seed the Kelurahan table first.");
 | |
|         }
 | |
| 
 | |
|         // Get available JenisKegiatan IDs from the database
 | |
|         $jenisKegiatanIds = \App\Models\JenisKegiatan::pluck('JenisKegiatanId')->toArray();
 | |
| 
 | |
|         // Make sure we have JenisKegiatan records
 | |
|         if (empty($jenisKegiatanIds)) {
 | |
|             throw new \Exception("No JenisKegiatan records found. Please seed the JenisKegiatan table first.");
 | |
|         }
 | |
| 
 | |
|         // Get available Verifikator IDs from the database
 | |
|         $verifikatorIds = \App\Models\Verifikator::pluck('VerifikatorId')->toArray();
 | |
| 
 | |
|         // Make sure we have Verifikator records
 | |
|         if (empty($verifikatorIds)) {
 | |
|             throw new \Exception("No Verifikator records found. Please seed the Verifikator table first.");
 | |
|         }
 | |
| 
 | |
|         for ($i = 0; $i < 100; $i++) {
 | |
|             $data[] = [
 | |
|                 'NomorInduk' => $faker->unique()->numerify('P########'),
 | |
|                 'JenisKegiatanId' => $faker->randomElement($jenisKegiatanIds),
 | |
|                 'NamaPerusahaan' => $faker->company,
 | |
|                 'Alamat' => $faker->address,
 | |
|                 'KelurahanId' => $faker->randomElement($kelurahanIds),
 | |
|                 'KodePos' => $faker->postcode,
 | |
|                 'Telepon' => $faker->phoneNumber,
 | |
|                 'JenisDokILId' => $faker->numberBetween(1, 3),
 | |
|                 'VerifikatorId' => $faker->randomElement($verifikatorIds),
 | |
|                 'IsPublish' => $faker->boolean,
 | |
|                 'Bujur' => $faker->longitude,
 | |
|                 'CPNama' => $faker->name,
 | |
|                 'CPTelepon' => $faker->phoneNumber,
 | |
|                 'ILNomor' => $faker->bothify('IL-####/???/####'),
 | |
|                 'ILTanggal' => $faker->date(),
 | |
|                 'JenisDokILId' => $faker->numberBetween(1, 3),
 | |
|                 'VerifikatorId' => $faker->numberBetween(1, 10),
 | |
|                 'IsPublish' => $faker->boolean,
 | |
|                 'ILDokumen' => $faker->randomElement(['dokumen1.pdf', 'dokumen2.pdf', 'dokumen3.pdf']),
 | |
|                 'ReportLocked' => $faker->boolean,
 | |
|                 'created_at' => $timestamp,
 | |
|                 'updated_at' => $timestamp,
 | |
|             ];
 | |
| 
 | |
|             // Insert in chunks to avoid memory issues
 | |
|             if (($i + 1) % 100 === 0 || $i === 99) {
 | |
|                 Perusahaan::insert($data);
 | |
|                 $data = [];
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         // Insert any remaining records
 | |
|         if (!empty($data)) {
 | |
|             Perusahaan::insert($data);
 | |
|         }
 | |
|     }
 | |
| }
 |