61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Student;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Seeder;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class StudentSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$religions = ['islam', 'kristen', 'katolik', 'hindu', 'buddha'];
|
|
$parentRole = Role::where('name', 'parent')->firstOrFail();
|
|
|
|
for ($i = 1; $i <= 20; $i++) {
|
|
$gender = $i % 2 == 0 ? 'L' : 'P';
|
|
$religion = $religions[array_rand($religions)];
|
|
$nis = '24' . str_pad($i, 4, '0', STR_PAD_LEFT);
|
|
$birthDate = Carbon::now()->subYears(rand(15, 18))->subMonths(rand(1, 12));
|
|
$parentName = 'Orang Tua Siswa ' . $i;
|
|
$parentEmail = 'parent' . $i . '@example.com';
|
|
$parentPhone = '0813' . rand(1000000, 9999999);
|
|
|
|
$birthDateParse = Carbon::parse($birthDate);
|
|
$password = $birthDateParse->format('dmY') . $nis;
|
|
|
|
$parentUser = User::firstOrCreate(
|
|
['email' => $parentEmail],
|
|
[
|
|
'name' => $parentName,
|
|
'password' => bcrypt($password),
|
|
'phone' => $parentPhone,
|
|
]
|
|
);
|
|
|
|
$parentUser->assignRole($parentRole);
|
|
|
|
Student::firstOrCreate(
|
|
['nis' => $nis],
|
|
[
|
|
'full_name' => 'Siswa ' . $i,
|
|
'gender' => $gender,
|
|
'birth_date' => $birthDate,
|
|
'birth_place' => 'Kota ' . chr(65 + rand(0, 25)),
|
|
'address' => 'Jl. Contoh No.' . $i,
|
|
'phone' => '0812' . rand(1000000, 9999999),
|
|
'parent_name' => $parentName,
|
|
'religion' => $religion,
|
|
'parent_phone' => $parentPhone,
|
|
'email' => $parentEmail,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|