migrant-web/database/seeders/WorkerSeeder.php
2026-06-03 14:22:56 +05:30

239 lines
9.0 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class WorkerSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$workers = [
[
'name' => 'John Doe',
'email' => 'john.doe@example.com',
'phone' => '+971 50 111 2222',
'nationality' => 'India',
'age' => 30,
'salary' => 2500.00,
'availability' => 'Immediate',
'experience' => '5+ Years',
'religion' => 'Christian',
'bio' => '',
'category_id' => 1, // Electrician
'verified' => true,
'status' => 'active',
],
[
'name' => 'Ali Hassan',
'email' => 'ali.hassan@example.com',
'phone' => '+971 50 333 4444',
'nationality' => 'Pakistan',
'age' => 28,
'salary' => 2000.00,
'availability' => '1 Month Notice',
'experience' => '3 Years',
'religion' => 'Muslim',
'bio' => 'Skilled mason with experience in block work and plastering.',
'category_id' => 2, // Mason
'verified' => true,
'status' => 'active',
],
[
'name' => 'Maria Santos',
'email' => 'maria.santos@example.com',
'phone' => '+971 50 555 6666',
'nationality' => 'Philippines',
'age' => 32,
'salary' => 1800.00,
'availability' => 'Immediate',
'experience' => '5+ Years',
'religion' => 'Christian',
'bio' => 'Experienced nanny with 6 years working with expatriate families in Dubai. Certified in pediatric first aid.',
'category_id' => 8, // Childcare
'verified' => true,
'status' => 'active',
],
[
'name' => 'Lakshmi Sharma',
'email' => 'lakshmi.sharma@example.com',
'phone' => '+971 50 777 8888',
'nationality' => 'India',
'age' => 38,
'salary' => 1600.00,
'availability' => '2 Weeks',
'experience' => '3-5 Years',
'religion' => 'Hindu',
'bio' => 'Patient caregiver specializing in elderly assistance, mobility support, and vegetarian cooking.',
'category_id' => 11, // Elderly Care
'verified' => true,
'status' => 'active',
],
[
'name' => 'Siti Aminah',
'email' => 'siti.aminah@example.com',
'phone' => '+971 50 999 0000',
'nationality' => 'Indonesia',
'age' => 29,
'salary' => 1400.00,
'availability' => 'Immediate',
'experience' => '3-5 Years',
'religion' => 'Muslim',
'bio' => 'Hardworking and meticulous housekeeper with excellent references from Abu Dhabi households.',
'category_id' => 9, // Housekeeping
'verified' => true,
'status' => 'active',
],
[
'name' => 'Grace Osei',
'email' => 'grace.osei@example.com',
'phone' => '+971 50 222 3333',
'nationality' => 'Ghana',
'age' => 26,
'salary' => 1500.00,
'availability' => '1 Month',
'experience' => '1-2 Years',
'religion' => 'Christian',
'bio' => 'Energetic and educated nanny. Fluent in English, great with toddlers and assisting with homework.',
'category_id' => 8, // Childcare
'verified' => false,
'status' => 'active',
],
[
'name' => 'Anoma Perera',
'email' => 'anoma.perera@example.com',
'phone' => '+971 50 444 5555',
'nationality' => 'Sri Lanka',
'age' => 41,
'salary' => 2200.00,
'availability' => 'Immediate',
'experience' => '5+ Years',
'religion' => 'Buddhist',
'bio' => 'Professional domestic cook skilled in Arabic, Continental, and Asian cuisine. Highly organized.',
'category_id' => 10, // Cooking
'verified' => true,
'status' => 'active',
],
[
'name' => 'Ramesh Thapa',
'email' => 'ramesh.thapa@example.com',
'phone' => '+971 50 666 7777',
'nationality' => 'Nepal',
'age' => 36,
'salary' => 2500.00,
'availability' => '2 Weeks',
'experience' => '5+ Years',
'religion' => 'Hindu',
'bio' => 'Valid UAE driving license with clean record. Familiar with all Dubai and Sharjah school routes.',
'category_id' => 6, // Driver
'verified' => true,
'status' => 'active',
],
];
// Dynamic Category Resolution
$categoryMapping = [
1 => 'Electrician',
2 => 'Mason',
3 => 'Plumber',
4 => 'Cleaner',
5 => 'Site Supervisor',
6 => 'Driver',
7 => 'General Helper',
8 => 'Childcare',
9 => 'Housekeeping',
10 => 'Cooking',
11 => 'Elderly Care',
];
$categoryIds = [];
foreach ($categoryMapping as $oldId => $name) {
$cat = \Illuminate\Support\Facades\DB::table('worker_categories')->where('name', $name)->first();
if (!$cat) {
$catId = \Illuminate\Support\Facades\DB::table('worker_categories')->insertGetId([
'name' => $name,
'created_at' => now(),
'updated_at' => now(),
]);
} else {
$catId = $cat->id;
}
$categoryIds[$oldId] = $catId;
}
// Dynamic Skill Resolution
$skillIds = \Illuminate\Support\Facades\DB::table('skills')->pluck('id')->toArray();
if (empty($skillIds)) {
foreach (['cooking', 'driving', 'childcare', 'cleaning', 'elderly care', 'gardening'] as $skillName) {
$skillIds[] = \Illuminate\Support\Facades\DB::table('skills')->insertGetId([
'name' => $skillName,
'created_at' => now(),
'updated_at' => now(),
]);
}
}
$sId1 = $skillIds[0] ?? 1;
$sId2 = $skillIds[1] ?? 2;
foreach ($workers as $workerData) {
$resolvedCategoryId = $categoryIds[$workerData['category_id']] ?? $workerData['category_id'];
// Exclude email duplicates to avoid unique constraint violations
if (\Illuminate\Support\Facades\DB::table('workers')->where('email', $workerData['email'])->exists()) {
continue;
}
$workerId = \Illuminate\Support\Facades\DB::table('workers')->insertGetId(array_merge($workerData, [
'category_id' => $resolvedCategoryId,
'created_at' => now(),
'updated_at' => now(),
]));
// Seed Documents
\Illuminate\Support\Facades\DB::table('worker_documents')->insert([
[
'worker_id' => $workerId,
'type' => 'passport',
'number' => 'P' . rand(100000, 999999),
'issue_date' => '2020-01-01',
'expiry_date' => '2030-01-01',
'ocr_accuracy' => 95.5,
'created_at' => now(),
'updated_at' => now(),
],
[
'worker_id' => $workerId,
'type' => 'visa',
'number' => 'V' . rand(100000, 999999),
'issue_date' => '2022-01-01',
'expiry_date' => '2025-01-01',
'ocr_accuracy' => 98.0,
'created_at' => now(),
'updated_at' => now(),
]
]);
// Seed Skills using resolved IDs
\Illuminate\Support\Facades\DB::table('worker_skills')->insert([
[
'worker_id' => $workerId,
'skill_id' => $sId1,
'created_at' => now(),
'updated_at' => now(),
],
[
'worker_id' => $workerId,
'skill_id' => $sId2,
'created_at' => now(),
'updated_at' => now(),
]
]);
}
}
}