46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\TaskCollection;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class TaskCollectionFactory extends Factory
|
|
{
|
|
protected $model = TaskCollection::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$categories = ['Allgemein', 'Vorbereitung', 'Event-Tag', 'Aufräumen', 'Follow-up'];
|
|
$colors = ['#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6'];
|
|
|
|
return [
|
|
'tenant_id' => Tenant::factory(),
|
|
'name' => $this->faker->randomElement($categories),
|
|
'description' => $this->faker->sentence(),
|
|
'is_default' => $this->faker->boolean(20),
|
|
'position' => $this->faker->numberBetween(1, 10),
|
|
];
|
|
}
|
|
|
|
public function withTasks(int $count = 3): static
|
|
{
|
|
return $this->afterCreating(function (TaskCollection $collection) use ($count) {
|
|
\App\Models\Task::factory($count)
|
|
->create(['tenant_id' => $collection->tenant_id])
|
|
->each(function ($task) use ($collection) {
|
|
$task->taskCollection()->associate($collection);
|
|
$task->save();
|
|
});
|
|
});
|
|
}
|
|
|
|
public function default(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'is_default' => true,
|
|
'position' => 1,
|
|
]);
|
|
}
|
|
} |