Files

105 lines
2.4 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Database\Factories;
use App\Models\Idea;
use App\Models\Project;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class IdeaFactory extends Factory
{
protected $model = Idea::class;
public function definition(): array
{
return [
'title' => fake()->sentence(4),
'description' => fake()->optional()->paragraph(),
'status' => fake()->randomElement(Idea::STATUSES),
'project_id' => null, // Optional link to project
'priority' => fake()->numberBetween(0, 10),
'category' => fake()->optional()->randomElement(Idea::CATEGORIES),
'tags' => fake()->optional()->words(3, true),
'user_id' => User::factory(),
];
}
public function asNew(): static
{
return $this->state(fn () => [
'status' => 'new',
]);
}
public function considered(): static
{
return $this->state(fn () => [
'status' => 'considered',
]);
}
public function planned(): static
{
return $this->state(fn () => [
'status' => 'planned',
]);
}
public function rejected(): static
{
return $this->state(fn () => [
'status' => 'rejected',
]);
}
public function implemented(): static
{
return $this->state(fn () => [
'status' => 'implemented',
]);
}
public function feature(): static
{
return $this->state(fn () => [
'category' => 'feature',
]);
}
public function improvement(): static
{
return $this->state(fn () => [
'category' => 'improvement',
]);
}
public function bugfix(): static
{
return $this->state(fn () => [
'category' => 'bugfix',
]);
}
public function withProject(Project $project = null): static
{
return $this->state(fn () => [
'project_id' => $project ? $project->id : Project::factory()->create()->id,
]);
}
public function highPriority(): static
{
return $this->state(fn () => [
'priority' => fake()->numberBetween(7, 10),
]);
}
public function withTags(array $tags): static
{
return $this->state(fn () => [
'tags' => implode(',', $tags),
]);
}
}