You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
<?php |
|
|
|
namespace Database\Seeders; |
|
|
|
use Illuminate\Support\Str; |
|
use Illuminate\Database\Seeder; |
|
use Illuminate\Support\Facades\DB; |
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents; |
|
|
|
class PetiSeeder extends Seeder |
|
{ |
|
/** |
|
* Run the database seeds. |
|
*/ |
|
// public function run(): void |
|
// { |
|
// // |
|
// } |
|
public function run() |
|
{ |
|
// Generate 5 dummy data |
|
for ($i = 0; $i < 5; $i++) { |
|
DB::table('petis')->insert([ |
|
'id' => Str::uuid(), |
|
'id_incre' => $i + 1, // Increment id_incre from 1 to 5 |
|
'tipe_peti_id' => $this->getRandomId('type_petis'), |
|
'warna' => 'Dummy Warna ' . ($i + 1), |
|
'fix_lot' => 'Dummy Fix Lot ' . ($i + 1), |
|
'packing_no' => rand(1, 100), |
|
'customer_id' => $this->getRandomId('customers'), |
|
'jumlah' => rand(1, 10), |
|
'date_pembuatan' => now(), |
|
'warehouse_id' => $this->getRandomId('m_warehouses'), |
|
'kondisipeti_id' => $this->getRandomId('kondisi_petis'), |
|
'created_at' => now(), |
|
'updated_at' => now(), |
|
'created_by' => 'Seeder', |
|
'updated_by' => 'Seeder', |
|
]); |
|
} |
|
} |
|
|
|
/** |
|
* Get a random ID from a specific table |
|
* |
|
* @param string $tableName |
|
* @return string|null |
|
*/ |
|
private function getRandomId($tableName) |
|
{ |
|
$record = DB::table($tableName)->inRandomOrder()->first(); |
|
|
|
return $record ? $record->id : null; |
|
} |
|
}
|
|
|