52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Models\User;
|
|
use App\Models\Worker;
|
|
use App\Models\Conversation;
|
|
use App\Models\Message;
|
|
|
|
class ConversationSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$employer = User::where('role', 'employer')->first();
|
|
if (!$employer) {
|
|
return;
|
|
}
|
|
|
|
$workers = Worker::where('status', 'active')->take(3)->get();
|
|
if ($workers->isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
// Conversation 1: with Worker 1 (John Doe)
|
|
$w1 = $workers->get(0);
|
|
if ($w1) {
|
|
Conversation::create([
|
|
'employer_id' => $employer->id,
|
|
'worker_id' => $w1->id,
|
|
'created_at' => now()->subHours(2),
|
|
'updated_at' => now()->subHours(2),
|
|
]);
|
|
}
|
|
|
|
// Conversation 2: with Worker 2 (Ali Hassan)
|
|
$w2 = $workers->get(1);
|
|
if ($w2) {
|
|
Conversation::create([
|
|
'employer_id' => $employer->id,
|
|
'worker_id' => $w2->id,
|
|
'created_at' => now()->subHour(),
|
|
'updated_at' => now()->subHour(),
|
|
]);
|
|
}
|
|
}
|
|
}
|