Files
fotospiel-app/database/factories/TaskFactory.php

56 lines
1.5 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Task;
use App\Models\TaskCollection;
use App\Models\Tenant;
use Illuminate\Database\Eloquent\Factories\Factory;
class TaskFactory extends Factory
{
protected $model = Task::class;
public function definition(): array
{
return [
'tenant_id' => Tenant::factory(),
'title' => $this->faker->sentence(4),
'description' => $this->faker->paragraph(),
'due_date' => $this->faker->dateTimeBetween('now', '+1 month'),
'is_completed' => $this->faker->boolean(20), // 20% chance completed
'collection_id' => null,
];
}
public function completed(): static
{
return $this->state(fn (array $attributes) => [
'is_completed' => true,
'completed_at' => now(),
]);
}
public function urgent(): static
{
return $this->state(fn (array $attributes) => [
'priority' => 'urgent',
'due_date' => $this->faker->dateTimeBetween('now', '+3 days'),
]);
}
public function withCollection(): static
{
return $this->state(fn (array $attributes) => [
'collection_id' => TaskCollection::factory(),
]);
}
public function assignedToEvent(): static
{
return $this->afterCreating(function (Task $task) {
$event = \App\Models\Event::factory()->create(['tenant_id' => $task->tenant_id]);
$task->assignedEvents()->attach($event);
});
}
}