Files
fotospiel-app/database/factories/TaskFactory.php
Codex Agent fa33e7cbcf Fix Event & EventType resource issues and apply formatting
- Fix EventType deletion error handling (constraint violations)
- Fix Event update error (package_id column missing)
- Fix Event Type dropdown options (JSON display issue)
- Fix EventPackagesRelationManager query error
- Add missing translations for deletion errors
- Apply Pint formatting
2026-01-21 10:34:06 +01:00

72 lines
2.0 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Task;
use App\Models\TaskCollection;
use App\Models\Tenant;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class TaskFactory extends Factory
{
protected $model = Task::class;
public function definition(): array
{
$title = ucfirst($this->faker->unique()->words(4, true));
$description = $this->faker->paragraph(2);
return [
'tenant_id' => Tenant::factory(),
'slug' => Str::slug($title.'-'.$this->faker->unique()->numberBetween(1, 9999)),
'title' => [
'de' => $title,
'en' => $title,
],
'description' => [
'de' => $description,
'en' => $description,
],
'example_text' => [
'de' => $this->faker->sentence(),
'en' => $this->faker->sentence(),
],
'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);
});
}
}