45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\ClassRoom;
|
|
use App\Models\Student;
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class StudentSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$classrooms = ClassRoom::all();
|
|
$religions = ['islam', 'kristen', 'katolik', 'hindu', 'buddha'];
|
|
|
|
foreach ($classrooms as $classroom) {
|
|
for ($i = 1; $i <= 20; $i++) {
|
|
$gender = $i % 2 == 0 ? 'L' : 'P';
|
|
$religion = $religions[array_rand($religions)];
|
|
$nis = $classroom->class_level . str_pad($i, 3, '0', STR_PAD_LEFT);
|
|
|
|
Student::firstOrCreate(
|
|
['nis' => $nis], // Cek berdasarkan NIS
|
|
[
|
|
'full_name' => 'Siswa ' . $classroom->class_name . ' ' . $i,
|
|
'gender' => $gender,
|
|
'birth_date' => now()->subYears(rand(15, 18))->subMonths(rand(1, 12)),
|
|
'birth_place' => 'Kota ' . chr(65 + rand(0, 25)),
|
|
'address' => 'Jl. Contoh No.' . $i,
|
|
'phone' => '0812' . rand(1000000, 9999999),
|
|
'class_id' => $classroom->id,
|
|
'parent_name' => 'Orang Tua Siswa ' . $i,
|
|
'religion' => $religion,
|
|
'parent_phone' => '0813' . rand(1000000, 9999999),
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|