2026-09-17 23:01:26 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
|
|
use App\Models\Folder;
|
|
|
|
|
use App\Models\Todo;
|
|
|
|
|
use App\Models\User;
|
2026-09-21 00:33:10 -07:00
|
|
|
use App\TodoStatus;
|
2026-09-17 23:01:26 -07:00
|
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
|
|
|
{
|
|
|
|
|
use WithoutModelEvents;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Seed the application's database.
|
|
|
|
|
*/
|
|
|
|
|
public function run(): void
|
|
|
|
|
{
|
|
|
|
|
$this->call(BaseDatabaseSeeder::class);
|
|
|
|
|
|
2026-09-21 00:33:10 -07:00
|
|
|
$user = User::updateOrCreate(
|
|
|
|
|
['email' => 'test@example.com'],
|
|
|
|
|
[
|
|
|
|
|
'name' => 'Test User',
|
|
|
|
|
'password' => 'password',
|
|
|
|
|
'is_admin' => true,
|
|
|
|
|
],
|
|
|
|
|
);
|
2026-09-17 23:01:26 -07:00
|
|
|
|
|
|
|
|
$work = $this->createTopLevelFolder($user, 'Work');
|
|
|
|
|
$business = $this->createTopLevelFolder($user, 'Business');
|
|
|
|
|
$personal = $this->createTopLevelFolder($user, 'Personal');
|
|
|
|
|
|
|
|
|
|
$workCompanies = [
|
|
|
|
|
$this->createChildFolder($work, 'Acme Corp'),
|
|
|
|
|
$this->createChildFolder($work, 'Globex'),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$businessTypes = [
|
|
|
|
|
$this->createChildFolder($business, 'Invoices'),
|
|
|
|
|
$this->createChildFolder($business, 'Prospects'),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$personalTypes = [
|
|
|
|
|
$this->createChildFolder($personal, 'Health'),
|
|
|
|
|
$this->createChildFolder($personal, 'Home'),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$folders = collect([$work, $business, $personal])
|
|
|
|
|
->merge($workCompanies)
|
|
|
|
|
->merge($businessTypes)
|
|
|
|
|
->merge($personalTypes);
|
|
|
|
|
|
|
|
|
|
$samples = [
|
|
|
|
|
['Work out the Q4 roadmap', 'Acme Corp', 0, 'open'],
|
|
|
|
|
['Review Globex contract', 'Globex', 2, 'overdue'],
|
|
|
|
|
['Send invoice for consulting work', 'Invoices', 1, 'due-today'],
|
|
|
|
|
['Follow up on new prospect', 'Prospects', 5, 'open'],
|
|
|
|
|
['Book dentist appointment', 'Health', -1, 'overdue'],
|
|
|
|
|
['Fix the garage door', 'Home', 7, 'open'],
|
|
|
|
|
['Plan summer vacation', 'Personal', null, 'open'],
|
|
|
|
|
['Consolidate expense reports', 'Business', 10, 'completed'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$foldersByName = $folders->keyBy(fn (Folder $folder) => $folder->name);
|
|
|
|
|
|
|
|
|
|
foreach ($samples as [$description, $folderName, $daysFromToday, $status]) {
|
2026-09-21 00:33:10 -07:00
|
|
|
$todo = Todo::firstOrCreate(
|
|
|
|
|
['user_id' => $user->id, 'folder_id' => $foldersByName[$folderName]->id, 'description' => $description],
|
|
|
|
|
['status' => TodoStatus::Open],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($daysFromToday === null) {
|
|
|
|
|
$todo->update(['due_date' => null]);
|
|
|
|
|
} else {
|
|
|
|
|
$todo->update(['due_date' => today()->addDays($daysFromToday)]);
|
|
|
|
|
}
|
2026-09-17 23:01:26 -07:00
|
|
|
|
|
|
|
|
if ($status === 'overdue') {
|
|
|
|
|
$todo->update(['due_date' => today()->subDays(3)]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($status === 'completed') {
|
2026-09-21 00:33:10 -07:00
|
|
|
$todo->update([
|
|
|
|
|
'status' => TodoStatus::Completed,
|
|
|
|
|
'completed_at' => now()->subDay(),
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
$todo->update(['completed_at' => null]);
|
2026-09-17 23:01:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createTopLevelFolder(User $user, string $name): Folder
|
|
|
|
|
{
|
2026-09-21 00:33:10 -07:00
|
|
|
return Folder::firstOrCreate(
|
|
|
|
|
['user_id' => $user->id, 'name' => $name, 'parent_id' => null],
|
|
|
|
|
['color' => fake()->optional()->randomElement(Folder::COLORS)],
|
|
|
|
|
);
|
2026-09-17 23:01:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createChildFolder(Folder $parent, string $name): Folder
|
|
|
|
|
{
|
2026-09-21 00:33:10 -07:00
|
|
|
return Folder::firstOrCreate(
|
|
|
|
|
['user_id' => $parent->user_id, 'name' => $name, 'parent_id' => $parent->id],
|
|
|
|
|
['color' => fake()->optional()->randomElement(Folder::COLORS)],
|
|
|
|
|
);
|
2026-09-17 23:01:26 -07:00
|
|
|
}
|
|
|
|
|
}
|