migrant-web/database/seeders/JobPostSeeder.php
2026-05-20 13:26:43 +05:30

71 lines
2.3 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class JobPostSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Resolve the first employer user dynamically
$employerId = \App\Models\User::where('role', 'employer')->first()->id ?? 2;
$jobs = [
[
'employer_id' => $employerId,
'title' => 'Senior Electrician for Villa Project',
'category_id' => 1, // Electrician
'workers_needed' => 2,
'job_type' => 'Full Time',
'location' => 'Dubai Marina',
'salary' => 3000.00,
'start_date' => '2026-06-01',
'description' => 'Need an experienced electrician for a luxury villa project.',
'status' => 'active',
],
[
'employer_id' => $employerId,
'title' => 'Mason for Commercial Building',
'category_id' => 2, // Mason
'workers_needed' => 5,
'job_type' => 'Contract',
'location' => 'Business Bay',
'salary' => 2500.00,
'start_date' => '2026-06-15',
'description' => 'Looking for skilled masons for a commercial project.',
'status' => 'active',
],
];
foreach ($jobs as $jobData) {
$jobId = \Illuminate\Support\Facades\DB::table('job_posts')->insertGetId(array_merge($jobData, [
'created_at' => now(),
'updated_at' => now(),
]));
// Seed Applications (assuming Worker ID 1 and 2 exist)
\Illuminate\Support\Facades\DB::table('job_applications')->insert([
[
'job_id' => $jobId,
'worker_id' => 1,
'status' => 'applied',
'created_at' => now(),
'updated_at' => now(),
],
[
'job_id' => $jobId,
'worker_id' => 2,
'status' => 'shortlisted',
'created_at' => now(),
'updated_at' => now(),
]
]);
}
}
}