Files
fotospiel-app/database/factories/EventFactory.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

67 lines
1.8 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Event;
use App\Models\EventType;
use App\Models\Tenant;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class EventFactory extends Factory
{
protected $model = Event::class;
public function definition(): array
{
$name = $this->faker->words(3, true);
$slug = Str::slug($name);
return [
'tenant_id' => Tenant::factory(),
'event_type_id' => EventType::factory(),
'name' => $name,
'slug' => $slug,
'description' => $this->faker->paragraph(),
'date' => $this->faker->dateTimeBetween('now', '+6 months'),
'location' => $this->faker->address(),
'max_participants' => $this->faker->numberBetween(50, 500),
'settings' => null,
'is_active' => true,
'join_link_enabled' => true,
'photo_upload_enabled' => true,
'task_checklist_enabled' => true,
];
}
public function inactive(): static
{
return $this->state(fn (array $attributes) => [
'is_active' => false,
]);
}
public function withTasks(int $count = 3): static
{
return $this->afterCreating(function (Event $event) use ($count) {
$event->tasks()->attach(
\App\Models\Task::factory($count)->create(['tenant_id' => $event->tenant_id])
);
});
}
public function past(): static
{
return $this->state(fn (array $attributes) => [
'date' => $this->faker->dateTimeBetween('-1 month', 'now'),
]);
}
public function upcoming(): static
{
return $this->state(fn (array $attributes) => [
'date' => $this->faker->dateTimeBetween('now', '+1 month'),
]);
}
}