114 lines
4.6 KiB
PHP
114 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Person;
|
|
use App\Models\Migration;
|
|
use App\Models\Residence;
|
|
use App\Models\Family;
|
|
use App\Models\Naturalization;
|
|
use App\Models\Internment;
|
|
use Illuminate\Database\Seeder;
|
|
use Faker\Factory as Faker;
|
|
use Carbon\Carbon;
|
|
|
|
class PersonSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$faker = Faker::create();
|
|
|
|
$this->command->info('Creating 100 sample Person records with related data...');
|
|
|
|
// Create 100 sample Person records
|
|
for ($i = 0; $i < 100; $i++) {
|
|
$surname = $faker->lastName;
|
|
$christianName = $faker->firstName;
|
|
|
|
// Randomly decide if person is deceased
|
|
$isDeceased = $faker->boolean(30); // 30% chance of being deceased
|
|
|
|
// Generate dates (past dates for birth, future or null for death)
|
|
$dob = $faker->dateTimeBetween('-100 years', '-20 years');
|
|
$dod = $isDeceased ? $faker->dateTimeBetween($dob, 'now') : null;
|
|
|
|
// Create the person record
|
|
$person = Person::create([
|
|
'surname' => $surname,
|
|
'christian_name' => $christianName,
|
|
'full_name' => $christianName . ' ' . $surname,
|
|
'date_of_birth' => $dob,
|
|
'place_of_birth' => $faker->city . ', ' . $faker->country,
|
|
'date_of_death' => $dod,
|
|
'occupation' => $faker->jobTitle,
|
|
'additional_notes' => $faker->boolean(70) ? $faker->paragraph(2) : null,
|
|
'reference' => $faker->boolean(50) ? 'REF-' . $faker->randomNumber(5) : null,
|
|
'id_card_no' => 'ID-' . $faker->unique()->randomNumber(8),
|
|
]);
|
|
|
|
// Create Migration data (80% chance)
|
|
if ($faker->boolean(80)) {
|
|
$arrivalAus = $faker->dateTimeBetween($dob, '-1 years');
|
|
$arrivalNT = $faker->dateTimeBetween($arrivalAus, '+2 years');
|
|
|
|
Migration::create([
|
|
'person_id' => $person->person_id,
|
|
'date_of_arrival_aus' => $arrivalAus,
|
|
'date_of_arrival_nt' => $arrivalNT,
|
|
'arrival_period' => $faker->randomElement(['Pre-WWII', 'Post-WWII', 'Modern Era']),
|
|
'data_source' => $faker->randomElement(['Archives', 'Family Records', 'Historical Documents', 'Interviews']),
|
|
]);
|
|
}
|
|
|
|
// Create Residence data (70% chance)
|
|
if ($faker->boolean(70)) {
|
|
Residence::create([
|
|
'person_id' => $person->person_id,
|
|
'town_or_city' => $faker->city,
|
|
'home_at_death' => $isDeceased ? $faker->streetAddress . ', ' . $faker->city : null,
|
|
]);
|
|
}
|
|
|
|
// Create Family data (60% chance)
|
|
if ($faker->boolean(60)) {
|
|
Family::create([
|
|
'person_id' => $person->person_id,
|
|
'names_of_parents' => $faker->boolean(70) ? $faker->name . ' & ' . $faker->name : null,
|
|
'names_of_children' => $faker->boolean(50) ? implode(', ', $faker->words($faker->numberBetween(1, 4))) : null,
|
|
]);
|
|
}
|
|
|
|
// Create Naturalization data (40% chance)
|
|
if ($faker->boolean(40)) {
|
|
$naturalizationDate = $faker->dateTimeBetween($dob, 'now');
|
|
|
|
Naturalization::create([
|
|
'person_id' => $person->person_id,
|
|
'date_of_naturalisation' => $naturalizationDate,
|
|
'no_of_cert' => 'CERT-' . $faker->unique()->randomNumber(6),
|
|
'issued_at' => $faker->city,
|
|
]);
|
|
}
|
|
|
|
// Create Internment data (10% chance - rare historical event)
|
|
if ($faker->boolean(10)) {
|
|
|
|
Internment::create([
|
|
'person_id' => $person->person_id,
|
|
'corps_issued' => $faker->randomElement(['Army', 'Navy', 'Air Force']),
|
|
'interned_in' => $faker->city,
|
|
'sent_to' => $faker->boolean(80) ? $faker->city : null,
|
|
'internee_occupation' => $faker->jobTitle,
|
|
'internee_address' => $faker->address,
|
|
'cav' => $faker->boolean(50) ? $faker->randomNumber(5) : null,
|
|
]);
|
|
}
|
|
}
|
|
|
|
$this->command->info('100 sample Person records created successfully with related data');
|
|
}
|
|
}
|